simple-http-server a simple HTTP server is based on NodeJS implemented base features need for debugging and testing javascript files.
Installation via npm:
npm install dev-http-server -g
// add reference to the moduleconstHttpSrv=require('dev-http-server');// create instanceconsthttpSrv=newHttpSrv();// add routehttpSrv.onPost('/page',(req,res)=>{res.writeHead(200,{'Content-Type': 'text/plain'});res.end('Page Two');});// run serverHttpSrv.run({ httpSrv });If server run correctly, you see following message:
Http Server started on 127.0.0.1:1337
HttpSrv.run method has following options
constoption={httpSrv: newHttpSrv(),// instance of HttpSrv objectaddress: '127.0.0.1',// IP address of server
port =1337,// Port of server };// add reference to the moduleconstHttpSrv=require('dev-http-server');// create instanceconsthttpSrv=newHttpSrv();// add static get response for select2 javascript componenthttpSrv.onGet('/select2',(req,res)=>{res.writeHead(200,{'Content-Type': 'application/json'});constobj={results: [{text: 'Group 1',children: [{id: 1,text: 'element 1'},{id: 2,text: 'element 2'},],},{text: 'Group 2',children: [{id: 3,text: 'element 3'},{id: 4,text: 'element 4'},],},{id: 5,text: 'element 5'},],};res.end(JSON.stringify(obj));});httpSrv.onPost('/page',(req,res)=>{res.writeHead(200,{'Content-Type': 'text/plain'});res.end('Page Two');});// run serverHttpSrv.run({ httpSrv });// add reference to the moduleconstHttpSrv=require('dev-http-server');// create instanceconsthttpSrv=newHttpSrv();// add for url /test all possible CRUD operation// GET, POST PUT DELETE// for GET /test server will return all content of file db.json// GET /test/1 return object with id=1// PUT add new object into db// POST update exist record in db.jsonhttpSrv.setJson('/test','src/db.json','id',false);// run serverHttpSrv.run({ httpSrv });// add reference to the moduleconstHttpSrv=require('dev-http-server');// create instanceconsthttpSrv=newHttpSrv();// for GET / server will return content of file index.html in folder /www// GET /file.html return content of file.html in folder /wwwhttpSrv.setStatic('/','/www','index.html');// run serverHttpSrv.run({ httpSrv });