Created
February 7, 2020 22:11
-
-
Save s-no1ukno/27ecb73452ea144a3fdb3b1fd98fddc7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express'); | |
const morgan = require('morgan'); | |
const cors = require('cors'); | |
const app = express(); | |
app.use(morgan('dev')); | |
app.use(cors()); | |
app.get('/', (req, res) => { | |
res.json({ | |
message: 'The server is ALIVE!!!' | |
}); | |
}); | |
function notFound(req, res, next) { | |
res.status(404); | |
const error = new Error('Not Found - ' + req.originalUrl); | |
next(error); | |
} | |
function errorHandler(err, req, res, next) { | |
res.status(res.statusCode || 500); | |
res.json({ | |
message: err.message, | |
stack: err.stack | |
}); | |
} | |
app.use(notFound); | |
app.use(errorHandler); | |
const port = process.env.PORT || 5000; | |
app.listen(port, () => { | |
console.log('Listening on port', port); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment