Home  >  Article  >  Web Front-end  >  node.js entry example helloworld detailed explanation_node.js

node.js entry example helloworld detailed explanation_node.js

WBOY
WBOYOriginal
2016-05-16 15:24:061662browse

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 line

Prompt 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.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn