I want to create a server and I want to get the script, CSS and the library.
I can get the file, but I don’t know how to get a directory:
app.get('/app.js', function(req, res) {
fs.readFile(__dirname + '/app.js', 'utf8', function(err, text){
res.end(text);
});
});
I want to get directory like above.
How can I do this?
If you are looking for function to read a directory
fs.readDirshould do the job for you. If you are looking for serving some static files it is better you use some framework such as “connect” (http://www.senchalabs.org/connect/static.html), instead of writing all by yourself.May you share what problem are you trying to solve? Someone can give you a much more precise answer in that case.
Please note I am also newbie to node.