Nodejs First Acquaintance

Source: Internet
Author: User

I. Introduction of NODEJS

1.Node is a server-side JavaScript interpreter.

The goal of 2.Node is to help programmers build highly scalable applications and write connection codes that can handle tens of thousands of simultaneous connections to a physical machine. Dealing with high concurrency and asynchronous I/O is one of the reasons that node is concerned by developers.

The 3.Node itself runs the Google V8 JavaScript engine , so speed and performance are great, and Node's encapsulation of it also improves its ability to process binary data. As a result, node not only uses V8, but also optimizes it to make it more resilient in a variety of environments.

4. Third-party extensions and modules play an important role in the use of node. NPM, for example, is the module's management tool, which installs various node packages (such as Express,redis, etc.) and publishes the packages it writes for node.

Second, installation

 Use homebrew to install under Mac:

1, Installation: Brew install node;

2, version: Node-v; Npm-v;

3. Upgrade Node:brew upgrade node

Third, Hello Word

1. New App.js

var http = require (' http '); Http.createserver (function (req, res) {    Res.writehead ($, {' Content-type ': ' Text/plain '});    Res.end (' Hello world\n ');}). Listen (1337, ' 127.0.0.1 '); Console.log (' Server running at http://127.0.0.1:1337/');

2. Terminal: node ~/documents/node/app.js

3, Browser: http://127.0.0.1:1337/View results Nodejs has been installed.

Iv. installation of Express

 1,sudo npm install-g Express for global installation.

Express provides project birth function terminal input

NPM Install express-generator-g for global installation

2. Create an Express project

Terminal input EXPRESS-E your project name

-E: For use with Ejs frame Express default to Jade (not recommended for novice use, where project configuration boot appears)

Express project has been created before you run it, be sure to install a dependency package, execute the command npm install

3. Operation

Execute command debug=app./bin/www;

Browser http://127.0.0.1:3000 Viewing results

    

Nodejs First Acquaintance

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.