Home > Web Front-end > JS Tutorial > body text

node.js entry example helloworld detailed explanation_node.js

WBOY
Release: 2016-05-16 15:24:06
Original
1702 people have browsed it

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'); //在控制台提示服务启动

Copy after login

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.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!