Skip to content

Instantly share code, notes, and snippets.

@chellimiller
Created July 19, 2018 02:21
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 chellimiller/055513d36bc7bdad95b65cfac98ce7ae to your computer and use it in GitHub Desktop.
Save chellimiller/055513d36bc7bdad95b65cfac98ce7ae to your computer and use it in GitHub Desktop.
Simple development server for a single page app
const http = require('http');
const url = require('url');
const fs = require('fs');
console.log('Server Started');
http.createServer(function(req, res){
fs.readFile('./index.html', (error, data) => {
if (error) {
res.writeHead(404, {'Content-type':'text/plain'});
res.write('Page Was Not Found');
} else {
res.writeHead(200, {'Content-type':'text/html'});
res.write(data);
}
res.end();
})
pathName= url.parse(req.url).pathname;
console.log(pathName);
}).listen(7000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment