I have this simple piece of code:
var http = require('http'), fs = require("fs");
function get(p) {
fs.readFile('.' + p,'utf8', function (err, cont) {
if (err) return "EERRRORRRRR";
else return cont;
})
}
http.createServer(function (request, response) {
var path = ((request.url==="/")?"/index.html":request.url);
console.log(get(path));
}).listen(80);
When I run and connect to the server, it logs undefined...
When I add a "console.log(cont)" like:
fs.readFile('.' + p,'utf8', function (err, cont) {
console.log(html)
if (err) return "EERRRORRRRR";
else return cont;
})
; it logs the correct contents, so why is the function returning undefined? the contents exists...
How would i fix this issue?
The originally context of the code was a simple web server, if you couldn't tell.