Learning Node – Express Public folder not working

The full URL I am trying to request: http://localhost:1337/public/serveme.txt

That’s your problem. Anything inside the directory you designate as static content is made available directly from the base URL. You need to request http://localhost:1337/serveme.txt instead.

If you want to only serve static files from /public you can pass a string as the first argument:

application.use("/public", express.static(path.join(__dirname, 'public')));

Leave a Comment