Skip to content

Instantly share code, notes, and snippets.

@matthewoestreich
Created April 28, 2019 01:33
Show Gist options
  • Save matthewoestreich/c51557b4858d6c75534d7965e0e3663f to your computer and use it in GitHub Desktop.
Save matthewoestreich/c51557b4858d6c75534d7965e0e3663f to your computer and use it in GitHub Desktop.
Simple boilerplate for Express [native logging requires 'chalk']
const express = require('express');
const app = express();
const chalk = require('chalk');
// eslint-disable-next-line no-console
const log = console.log;
const port = 8889;
app.use((req, res, next) => {
let h = req.hostname + req.url;
let m = req.method;
log(
chalk.red("REQUESET: ") +
chalk.blue("for: ") +
chalk.yellow(h) + " || " +
chalk.blue("method: ") +
chalk.yellow(m) +
" @" +
chalk.red(Date(Date.now()))
);
next();
});
app.use(express.static(__dirname + '/dist'));
app.get('/', (req, res) => {
res.sendFile(__dirname + '/index.html');
});
app.listen(port, () => {
log(chalk.red("App listening on port " + port + "\r\n"))
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment