Can not run my nodejs project Helloworld on Centos 7

April 2, 2019 543 views
Node.js CentOS

I installed NodeJS by following link:
https://www.digitalocean.com/community/tutorials/how-to-set-up-a-node-js-application-for-production-on-centos-7
But when I test my nodejs project HelloWorld, the system show errors:
File hello.js:
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(8080,'http://10.132.36.167');
console.log('Server running at http://10.132.36.167');
System show error:
Server running at http://10.132.36.167
events.js:174
throw er; // Unhandled 'error' event
^
Error: getaddrinfo ENOTFOUND http://10.132.36.167
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:56:26)
Emitted 'error' event at:
at GetAddrInfoReqWrap.doListen [as callback] (net.js:1448:12)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:56:17)
How can I fix this?
Thanks

1 Answer

Greetings!

Thanks for posting the question here so that others can learn from it as well. I believe the problem is with this line:

}).listen(8080,'http://10.132.36.167');

I believe it should instead read:

}).listen(8080,'10.132.36.167');

Just removing the protocol and putting the address only there.

Jarland

Have another answer? Share your knowledge.