It's okay. Churn node. js, ran a Hello world, and I hereby record it.
Installing the node. JS Environment under Windows
To the node website http://node.org can download to the installation package, I am Win7 64-bit, visit node official website, you can see the latest version is 0.12.7, click Install to download the MSI file, and then double-click to install.
The installation process is very simple, select all options, next.
MSI will put the NPM (node package Manager) together, will help you set the environment variables, add Node, NPM and so on to the path, so you just open the command line window, you can work.
A node. js directory is added to the Start menu, as shown in:
Clicking on the "node. js command Prompt" menu will go into node. JS's command-line environment, as shown in:
You can use node and NPM directly here.
If you enter node and enter into node's interactive environment, you can enter some JavaScript commands to look at, such as Console.log ("Hello node.js!"), responding to the HA. The effect of entering node is equivalent to clicking the node. JS menu in the Start menu.
If you enter NPM and return, you will see the use of NPM help, such as:
The basis of the environment is so, very simple, then we have to send a crazy, go usual, make a helloworld look.
HelloWorld website
The code is so simple:
// 引入http模块var http = require("http"); // 创建server,指定处理客户端请求的函数http.createServer( function(request, response) { response.writeHead(200, {"Content-Type": "text/plain"}); response.write("Hello World!"); response.end(); }).listen(8000); console.log("Hello World is listening at port 8000");
Save As Helloworld.js, and in the command-line environment of node. JS, go to the directory where Helloworld.js is located, execute node helloworld.js, and the site can run.
Our simple example, for any request, returns "Hello world!" Text string, you can enter "http://localhost:8000" in the browser to see the effect, I here is Jiangzi:
Nothing special, an ugly one, right. What about the HTTP module, see here http://nodejs.org/dist/v0.12.7/docs/api/http.html.
Well, that's how the magical world started ... The Start menu has the node. JS Documentation submenu, which allows you to go straight to the node. JS online document, where more excitement can begin.
Next time we look at how to install Express, use it to write a HelloWorld website. See what's different from here.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Getting Started with node. JS Development under Windows (1)