Last active
March 28, 2021 16:28
-
-
Save gforien/7e719f56e2df17ea74f441f90562ef52 to your computer and use it in GitHub Desktop.
Basic NodeJS Express boilerplate
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
require('dotenv-safe').config(); | |
// dependencies | |
const express = require('express'); | |
const bodyParser = require('body-parser'); | |
const cors = require('cors'); | |
// app | |
const app = express(); | |
const port = 8080; | |
app.use(cors()); | |
app.use(bodyParser.json()); | |
app.use(bodyParser.urlencoded({extended: true})); | |
app.use((req, res, next) => { | |
// logger middleware // | |
console.log(`${new Date().toISOString().replace(/T/, ' ').replace(/\..+/, '')} ${req.method} ${req.url}`); | |
next(); | |
}); | |
app.get('/', (req, res) => { | |
res.status(200).send("OK"); | |
}); | |
// routes | |
app.use(express.static(__dirname + "/static")); | |
app.listen(port, () => { | |
console.log(`App listening on port ${port}`); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment