0

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

Dharman
  • 30,962
  • 25
  • 85
  • 135
Zankhana Rana
  • 169
  • 2
  • 16
  • pic shown your server didn't started – hossein sedighian Feb 28 '19 at 20:02
  • So I edited my code to - 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) { console.log("ServerStarted"); fileServer.serve(req, res); }).listen(9000); and now on starting the server and navigating to http://localhost:9000 I see the Server Started message on command prompt. – Zankhana Rana Feb 28 '19 at 20:09

1 Answers1

0

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

Zankhana Rana
  • 169
  • 2
  • 16