Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const UserRepository = require('./UserRepository.js');
- const UserService = require('./UserService.js');
- const knex = require('knex');
- const express = require('express');
- const app = express();
- const db = knex({
- client: 'mysql',
- connection: {
- host: 'localhost',
- user: 'sample',
- password: 'secret',
- database: 'sample',
- },
- });
- const userRepository = new UserRepository(db);
- const userService = new UserService(userRepository);
- app.get('/users/:user_id', (request, response) => {
- const userId = request.params.user_id;
- userService.first(userId)
- .then((user) => {
- if (user) {
- return response.send(user);
- }
- response.status(404).send({
- error: 'User not found!',
- });
- });
- });
- app.listen(3000, () => console.log('Server running at port 3000'));
Add Comment
Please, Sign In to add comment