node. js initial Contact (i)

Source: Internet
Author: User

Originally still tangled in the end to learn which kind of background language, suddenly found that node. js is very fire, since can be praised by so many people, nature has his advantage. Baidu Encyclopedia to take a look, perhaps I understand the ability is too poor, and did not know a lot about node. js, probably know that node. js is a JavaScript to write the server-side script, and node is to provide JavaScript running platform. Well, still vague, well, the more you don't know, the more you can inspire my learning desire.

Today is formally started self-study, I found that for this new technology, learning resources seem to be not many, books and video screen are not many, and according to everyone, even the introductory book, it seems to be very laborious. A little surprised, is node. js so hard? Finally found a node to get started, and then download the installation of node. js, download install git Bash (Windows command tool, it is not clear whether this, first grope to see), OK, ready to work, then start to learn it.

As usual, the first example is Hello world, OK, here's the question, write the console.log ("Hello World"); What directory does this JS file exist in, which is the default search path for node? Perhaps I am too stupid, incredibly even this do not know, do not know if there are other beginners and I have the same problem. Since the problem has come to solve it, a variety of search to find a long time, not the results. Well, then I will try it myself, no outside the installation of those several directories, one of the always try to, sure enough to play all the installation directory is not right, a little bit of a crash. At this point I suddenly saw a message,Cann ' t find module ' C:\Users\dandan\hello.js ', Well, it turns out here, well, the first small example is finally done. Continue reading, build the server module:

var http = require ("http");
Http.createserver (function (request, response) {
Response.writehead ($, {"Content-type": "Text/plain"});
Response.Write ("Hello World");
Response.End ();
}). Listen (8888);

Well, just do it in the book, and look at it for as little as six hours. This 40-page book is over, and this is the first thing I've learned in a while:

1.node.js comes with an HTTP module that provides a function: Createserver, which returns an object that has a method called Listen, which has a parameter, Specifies the port number that the HTTP server listens on.

There are three built-in objects in the 2.node.js (three I know now): Require: Used to load and use other modules in the current module;

Exports: Public methods and properties for exporting modules;

Module: Many of the exported objects used to replace the current module.

3. A more complete server script consists of a server, a request routing, and a request handler.

4. Several grammars that have not been seen in javascript: querystring,fs,formidabled ... In view of the new contact, dare not to write, the few to learn more after the writing.

Summing up, although node. JS is also used JavaScript language, but the feeling is very different, it should be written in front of the idea is not the same, a little conversion, although the syntax code to write and check can understand the same, but the deep feeling that the idea is not up to, this is where the investigation. In addition, if there is a Linux foundation, to learn this should be a lot of help. Well, go ahead and read the book over again.

node. js initial Contact (i)

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.