I have a small problem when starting a script in the javascript language whose library is nodejs. The version of the node that I have installed is v6.11.1 and my computer is a Mac whose operating system is MacOS Sierra. The script that I'm trying to start is a simple hello world, since I'm starting:
var http = require('http');
http.createServer(function (req, res) {
res.writehead(200, {'Content-Type': 'text/plain'});
res.end('hola #backendpro\n');
}).listen(3000, '127.0.0.1');
console.log('Server running at [http.://127.0.0.1:3000/'][1]);
I write to the cd console and drag my folder where I have the script and then I type node and the name of my file that I want to run and the console returns a Server running at http.://127.0.0.1:3000/
until I open the browser and at the URL I type localhost: 3000 and the following appears on the console:
Mac-mini-of-Ivan: node ivan $ node holanode.js Server running at http.://127.0.0.1:3000//Users/ivan/Desktop/node/holanode.js:5 res.writehead (200, {'Content-Type': 'text / plain'}); ^
TypeError: res.writehead is not a function at Server. (/Users/ivan/Desktop/node/holanode.js:5:5) at emitTwo (events.js: 106: 13) at Server.emit (events.js: 191: 7) at HTTPParser.parserOnIncoming [as onIncoming] (_http_server.js: 546: 12) at HTTPParser.parserOnHeadersComplete (_http_common.js: 99: 23) Mac-mini-of-Ivan: node ivan $ node holanode.js Server running at link /Users/ivan/Desktop/node/holanode.js:5 res.writehead (200, {'Content-Type': 'text / plain'}); ^
TypeError: res.writehead is not a function at Server. (/Users/ivan/Desktop/node/holanode.js:5:5) at emitTwo (events.js: 106: 13) at Server.emit (events.js: 191: 7) at HTTPParser.parserOnIncoming [as onIncoming] (_http_server.js: 546: 12) at HTTPParser.parserOnHeadersComplete (_http_common.js: 99: 23)
and I do not know how to solve it, I have read many articles but none have helped me at all. I would be very grateful to the one who solves this problem for me.