Created
August 28, 2019 17:44
-
-
Save ekpangmichael/871d43b3c31b53a55a413d199c7c2c62 to your computer and use it in GitHub Desktop.
This file contains 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
import express from 'express'; | |
import cors from 'cors'; | |
import v1Routes from './routes'; | |
const app = express(); | |
const { PORT = 3000 } = process.env; | |
app.use(cors()); | |
app.use( | |
express.urlencoded({ | |
extended: false | |
}) | |
); | |
app.use(express.json()); | |
app.use(v1Routes); | |
// catch 404 and forward to error handler | |
app.use((req, res, next) => { | |
const err = new Error('Not Found'); | |
err.status = 404; | |
next(err); | |
}); | |
app.use((err, req, res, next) => { | |
res.status(err.status || 500).json({ | |
errors: { | |
message: err.message | |
} | |
}); | |
}); | |
app.listen(PORT, () => console.log(`App Listening on port ${PORT}`)); | |
export default app; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment