node-static file server error 404
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) { console.log("Server Started"); fileServer.serve(req, res); }).listen(9000); I start the server using node server.js on command prompt. This is what I see on the browser

There are no error messages on Developer Console
On command prompt, I see the message "Server Started" node -v 10.15.2 npm -v 6.4.1
Can anyone please tell me what is that I am doing wrong ?
Hi @zankhanarana9 !
This code works fine:
var http = require("http");
var nStatic = require("node-static");
var fileServer = new nStatic.Server();
http
.createServer(function(req, res) {
fileServer.serve(req, res);
})
.listen(9000);
I tried with the the following folder structure:
- node_modules
- index.js
- test.txt
When I start the server with node index.js, I can go to http://localhost:9000/test.txt and see the content of my txt file:

Can you show your folder structure? Most likely you forgot to add a file name you want to get from your folder in your address bar (see /test.txt in my example)
Looks like my directory structure was incorrect and so, the error 404. I added few folders and files and it works fine now.
Thank you.