Skip to content

Instantly share code, notes, and snippets.

@kazagkazag
Last active April 26, 2018 07:25
Show Gist options
  • Select an option

  • Save kazagkazag/99f8580a30942f3e6194 to your computer and use it in GitHub Desktop.

Select an option

Save kazagkazag/99f8580a30942f3e6194 to your computer and use it in GitHub Desktop.
Simple node server to serve static pages
//npm install express
var express = require('express');
var app = express();
var http = require('http');
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
app.get('/', function(req, res){
res.send('<h1>Hello world</h1>');
});
//if you have "page" directory and you want to use localhost:3000/index.html adress (index from page directory):
app.use(express.static('page'));
//if you have multiple directories, use localhost:3000/page/index.html and something like below:
//app.use('/page', express.static('page'));
app.listen(3000, function(){
console.log('listening on *:3000');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment