Skip to content

Instantly share code, notes, and snippets.

@intojs
Last active December 20, 2017 21:47
Show Gist options
  • Save intojs/c6b53330a12df6d41e5b107668a92ca1 to your computer and use it in GitHub Desktop.
Save intojs/c6b53330a12df6d41e5b107668a92ca1 to your computer and use it in GitHub Desktop.
FP in Node.js - index.js
import express from 'express';
import cors from 'cors';
import bodyParser from 'body-parser';
import {gistsRoute} from './gists.route.2';
const app = express();
const port = process.env.PORT || 3000;
const jsonParser = bodyParser.json();
app.use(cors());
app.use('/api/v1/gists', jsonParser, gistsRoute);
app.use((error, req, res, next) => {
console.error('handled error', error.stack);
return res
.status(500)
.send(error.message);
});
process
.on('unhandledRejection', (error) => {
console.error(`unhandledRejection ${error.stack}`);
process.exit(1);
})
.on('uncaughtException', (error) => {
console.error(`uncaughtException ${error.stack}`);
process.exit(1);
});
app.listen(port, () => {
console.info('Example app listening on port ' + port);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment