Create and initialize your a directory for your Express application.
$ mkdir node-knex-demo
$ cd node-knex-demo
$ npm init| # Given a start integer and an ending integer (both inclusive), write a function that returns the count (not the sum) of all integers in the range (except integers that contain the digit 5). | |
| # Examples: | |
| # csAnythingButFive(1, 5) -> 1, 2, 3, 4, -> 4 (there are 4 integers in the range that do not contain the digit 5) | |
| # csAnythingButFive(1, 9) -> 1, 2, 3, 4, 6, 7, 8, 9 -> 8 | |
| # csAnythingButFive(4, 17) -> 4,6,7,8,9,10,11,12,13,14,16,17 -> 12 | |
| # Notes: | |
| # The output can contain the digit 5. |
| // Use as a basic logger middleware in your server | |
| const logger = (req, res, next) => { | |
| const formatUrl = `${req.baseUrl}${req.url}` | |
| const log = `--------------------------- | |
| ${Date()} | |
| method: ${req.method} | |
| URL: ${formatUrl} | |
| status: ${res.statusCode} | |
| requester IP: ${req.ip} \n************` |
| //***********************500 error middleware***********// | |
| //eslint-disable-next-line | |
| server.use((err, req, res, next) => { | |
| res.status(err.status || 500).json({ | |
| message: err.message, | |
| devMessage: 'Something bad inside the server!' | |
| }); | |
| }); |