I'm just getting started with node.js. This is my first attempt ever and I'm having trouble reading from a txt file to the node.js terminal in windows 7. Using the Node.js application in windows, I typed "node sample.js" and the sample.js and sample.txt files are in a folder on my desktop but the node.exe application doesnt read the file. Also I'm not sure how it would know the directory path Any insight? Here's my code:
var fs = require("fs");
console.log("Starting");
fs.readFile("sample.txt", function(error, data) {
console.log("Contents of file: " + data);
});
console.log("Carrying on executing");
if(error) throw error;before you print out the data