Skip to content

Instantly share code, notes, and snippets.

@3dln
Last active June 24, 2020 05:39
Show Gist options
  • Save 3dln/2a12f2c858a9ab30ff53ff2168048635 to your computer and use it in GitHub Desktop.
Save 3dln/2a12f2c858a9ab30ff53ff2168048635 to your computer and use it in GitHub Desktop.
basic express boilerplate
const express = require('express')
const volleyball = require('volleyball')
const app = express()
app.use(volleyball)
app.get('/', (req, res) => {
res.json({
message: '🦄 Hello World! 🦄',
})
})
function notFound(req, res, next) {
res.status(404)
const err = new Error('Not Found - ' + req.originalUrl)
next(err)
}
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