Skip to content

Instantly share code, notes, and snippets.

@tehmachine
Last active February 13, 2017 01:24
Show Gist options
  • Save tehmachine/7463601672996d3ecc33c4e8cce5aa5b to your computer and use it in GitHub Desktop.
Save tehmachine/7463601672996d3ecc33c4e8cce5aa5b to your computer and use it in GitHub Desktop.
Simple Node.js server featuring Express.js
/**
* Basic Node + Express server file
* Written in ES6
*/
import express from 'express';
const app = express();
/**
* This html boilerplate can be moved in own module
*/
const html = `
<!doctype html>
<html>
<head>
<title>Boilerplate</title>
</head>
<body>
<h1>This is boilerplate</h1>
</body>
</html>
`;
app.get('/', (req, res) => {
res.send(html);
});
/**
* Set server host, port, and listen
*/
const host = process.env.HOST || 'localhost';
const port = process.env.PORT || '3000';
const server = app.listen(port, host, () => {
const host = server.address().address;
const port = server.address().port;
console.log('Server is running http://%s:%s', host, port);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment