Node Quick Start

Source: Internet
Author: User

Nodejs is a burgeoning technology, has been active in the major forums in recent years. In fact, Nodejs is just a new bottle of old wine, but some of its aggressive features make her seem mysterious. Nodejs uses JavaScript syntax, so when learning Nodejs, there must be a foundation for front-end learning.

Unlike popular technologies such as java,php, Nodejs uses a single-threaded, asynchronous programming model. The key to achieving this feature is the event loop mechanism. So one notable feature of Nodejs is that it saves thread overhead, but at the same time it's not good enough to use multicore CPUs. Let's meet Nodejs together.

To install node in the first place, the simplest way to install node is to download the. msi installation file on the node's official website, then double-click the installation directly.

Next, create a new app.js file to implement a simple HTTP server. Write the following code into the App.js file, then use node app.js to run the server, open the browser in the address bar input localhost:3000

  var http = require (' http ');

Http.createserve (function (req,res) {

Res.writehead (200,{' content-type ': ' text/html ');

Res.write ('

}). Listen (3000);

Build a file.js file below and write the code to read the file.

 var fs = require (' FS ');

Fs.readfile (' file.txt ', ' utf-8 ', function (err,data) {

if (err) {

Console.log (' Read file failed! ');

}else{

Console.log (data);

}

});

The above two examples are very simple, hoping to give the front-end students a little guidance.

  

  

Node Quick Start

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.