Last active
February 13, 2017 01:24
-
-
Save tehmachine/7463601672996d3ecc33c4e8cce5aa5b to your computer and use it in GitHub Desktop.
Simple Node.js server featuring Express.js
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
/** | |
* 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