Skip to content

Instantly share code, notes, and snippets.

@gforien
Last active March 28, 2021 16:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gforien/7e719f56e2df17ea74f441f90562ef52 to your computer and use it in GitHub Desktop.
Save gforien/7e719f56e2df17ea74f441f90562ef52 to your computer and use it in GitHub Desktop.
Basic NodeJS Express boilerplate
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