javascriptnode.jswebservernode-static

Localhost page cannot be found using node-static


I am trying to serve static files using node-static. Later I intend to run this as Windows service using nssm. I have run this before but don't know why, it doesn't work now.

Below is my code:

var http = require('http');

var nStatic = require('node-static');

var fileServer = new nStatic.Server(); ---> I also tried new nStatic.Server('filepath')
//setting middleware

http.createServer(function (req, res) { 
        fileServer.serve(req, res);
}).listen(9000);

I start the server using node server.js on command prompt. This is what I see

http://localhost:9000:
http://localhost:9000

Node -v 10.15.2 NPM -v 6.4.1


Solution

  • I had to use the full path until the folder to see the contents of it which now seems obvious as I localhost:9000 was never a file.

    I used something like this - http://localhost:9000/Test/test.txt