2

I am building one web application, nodejs is my webserver. I want to send response from nodejs for the images,html,css,js,other files.

I want to know which nodejs module is providing to serve my UI files without using fs module which is internally available in nodejs.

Constraint: If i use fs module or express which internally uses fs, if a new file is added it should be generated for the response.

Thanks

1
  • Could you explain your constraint more clearly? From what I read, you mean you want to serve not only files which exist when the server is started, but also files that are added later. Isn't that exactly what express.static does, look for the file and serve it if available? Commented Mar 9, 2012 at 14:40

1 Answer 1

3

You can use Express/Connect static middleware:

var app = require('express').createServer();
app.use(express.static(__dirname + '/public'));

app.listen(3000);

But the best way is configuring nginx or similar frontend server to proxy dynamic requests to node.js and direct return static files.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.