Skip to content

Instantly share code, notes, and snippets.

@amandeepmittal
Created November 4, 2018 16:07
Show Gist options
  • Save amandeepmittal/f6d5a02c1103ae96e92a99840fc54692 to your computer and use it in GitHub Desktop.
Save amandeepmittal/f6d5a02c1103ae96e92a99840fc54692 to your computer and use it in GitHub Desktop.
import express from 'express';
import cookieParser from 'cookie-parser';
import config from './server/config';
// DB connection
require('./server/config/dbConnection');
const app = express();
// middleware functions
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(cookieParser());
// Error handling middleware
app.use((err, req, res, next) => {
if (err.name === 'UnauthorizedError') {
res.status(401).json({ error: err.name + ':' + err.message });
}
});
app.listen(config.port, () => {
console.log(`🚀 at port ${config.port}`);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment