call static files in node.js code example
Example 1: how to use static file node js
app.use('/static', express.static(path.join(__dirname, 'public')))
Example 2: how can node js file be serve
var fs = require('fs'),
http = require('http');
http.createServer(function (req, res) {
fs.readFile(__dirname + req.url, function (err,data) {
if (err) {
res.writeHead(404);
res.end(JSON.stringify(err));
return;
}
res.writeHead(200);
res.end(data);
});
}).listen(8080);