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

Detailed introduction to nodejs (combination of multiple articles)_javascript skills

WBOY
Release: 2016-05-16 17:55:42
Original
926 people have browsed it

A series of changes began with Node.js, a JavaScript toolkit for writing high-performance web servers. Uniquely, Node.js assumes you are running it in a POSIX environment, Linux or Mac OS X. If you are under Windows, you need to install MinGW to get a POSIX-like environment. In Node, HTTP is primary. Node is optimized for creating http servers, so most of the examples and libraries you see online are focused on the web (http frameworks, template libraries, etc.).

First, go to http://nodejs.org to download and install. The version I downloaded is 0.6.6. Installation is very simple, just take the next step.
My installation directory is C:Program Files (x86)nodejs.

1. helloworld
Create a new file hello.js in the nodejs installation directory, and type a line of code in it

Copy Code The code is as follows:

console.log('hello, nodejs.') ;

Enter the command line console, enter the nodejs directory and type node hello.js

The console output "hello, nodejs."
2. Web version of helloworld
Create a new http.js in the nodejs installation directory, the code is as follows

Copy code The code is as follows:

var http = require("http");
http.createServer(function (request, response) {
response.writeHead(200, {"Content-Type": "text/html"});
response.write("Hello World!");
response.end ();
}).listen(8000);

Start the service in the command line and type node http.js

Then open the browser address bar and enter http://localhost:8000/. When you see Hello World! output on the page, it is successful.

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