Skip to content

Instantly share code, notes, and snippets.

@zackferrofields
Last active September 12, 2016 16:23
Show Gist options
  • Save zackferrofields/3e853f4823e5c09def1106de211b475c to your computer and use it in GitHub Desktop.
Save zackferrofields/3e853f4823e5c09def1106de211b475c to your computer and use it in GitHub Desktop.
Node static file server
const http = require('http');
const fs = require('fs');
const path = require('path');
const PORT = 8000;
const filePath = path.join(__dirname, 'index.html');
http.createServer((req, res) => {
res.writeHead(200, {'Content-Type': 'text/html'});
fs.createReadStream(filePath)
.on('data', data => res.write(data))
.on('end', () => res.end())
.on('error', () => res.end());
}).listen(PORT);
process.stdout.write(`Running on http://localhost:${PORT} \n`);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment