I just create a js file with the following code(exactly the code from official page):
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');
So, I install node from the 'Install' button in the official page too(for windows). But when I try to run the program it gives me the following:
but the strange thing is this:
You need to run that from your terminal (cmd) as opposed to Node's repl.
Try opening up a new terminal (Run -> CMD) and then executing:
node /your_file_name.js
To see which version you have installed, just execute:
node -v
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With