Example :
var directory='C:/node/my_modules/'
var http = require("http");
var url = require("url");
var fs = require("fs");
var fn = function(request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
fs.readFile(directory+'first.js','utf8',function(err,data){
if(err){
console.log(err)
console.log('cant openfile')
}
console.log(data)
})
response.end('_testcb("param")');
}
function start(){
http.createServer(fn).listen(1337);
console.log('start Server');
}
exports.start = start;
This example works ....In console i see data from file .
But when fs.readFile(directory+'my.txt' then error :
ENOENT, "no such file or directory"
How to get the contents of the my.txt file
my.txt is in the same directory as first.js