Skip to content

Instantly share code, notes, and snippets.

@connoro7
Created July 16, 2020 18:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save connoro7/df2d0f0daa233f170fe3b4d6c4da6d69 to your computer and use it in GitHub Desktop.
Save connoro7/df2d0f0daa233f170fe3b4d6c4da6d69 to your computer and use it in GitHub Desktop.
Express Starter
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: 'Hello World'
});
});
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