Home >Web Front-end >JS Tutorial >node.js entry example helloworld detailed explanation_node.js
The example in this article tells the node.js entry example helloworld. Share it with everyone for your reference, the details are as follows:
Save the following code as: server.js to the node directory under the E drive.
var http = require('http'); function myNode(request, response){ response.writeHead(200, {'Content-type':'text/plain'}); response.write('hello world'); //hello world response.end(); } http.createServer(myNode).listen(2222); //监听2222端口 console.log('Server has started'); //在控制台提示服务启动
Then enter node e:/node/server.js
on the windows command linePrompt that the service has started (Server has started), and then enter http://localhost:2222/ in the browser, you can see the effect as shown below.
The effect after successful execution
I hope this article will be helpful to everyone in node.js programming.