Node JS Connect file server not working as expected

I play with a simple Connect file server:

var connect = require('connect'), http = require('http'); connect() .use(connect.static('.')) .listen(3000); 

The index.html file loads when I am localhost:3000 . But I can not access another file as I expected. For example, the localhost:3000/json-parser.html returns Error: Forbidden followed by information about the Connect module (I will not include everything here unless requested because it is quite long and I suspect there is a simple answer to this question).

I changed my server by following the code here to serve the β€œpublic” folder in my directory:

 var connect = require('connect'), http = require('http'); connect() .use(connect.static('public')) .listen(3000); 

But I want to access scripts and files inside folders in the parent directory, which is impossible without putting everything in the "public" and without using my Connect file server. Is there a connection method for the directory service around it, given that the above does not work?

0
source share
1 answer

Try:

 var connect = require('connect'), http = require('http'); connect() .use(connect.static(__dirname)) .listen(3000); 

However, keep in mind that this will serve ALL files and subdirectories under the directory where you started server.js, which is usually not a good plan.

+1
source

All Articles