Introduction to node. js (2)

Source: Internet
Author: User
Tags install node
Introduction to node. js (2)
  • By poechant (blog.csdn.net/poechant)
1 how to recognize your node. js files?
Node-js|--- index.js|--- server.js

Index. JS:

var server = require("./server.js");server.start();

Server. JS:

var http = require("http");function start() {    http.createServer(function(request, response) {        console.log("Receive a request.");        response.writeHead(200, {"Content-Type": "text/plain"});        response.write("Hello World");        response.end();    }).listen(8765, "127.0.0.1");}exports.start = start;
2 how to install an external module?

It's very easy. the only requirement is that your computer has been connected to Internet. the method to install node. JS modules is just like the way to install softwares on Linux using apt-get, or on Mac OS X using marport.

npm install SOME_MODULE

What does NPM stand?

Perhaps it is nodejs pakage management.

3 how to use a module?

I guess you 've already known that.

var yourModule = require("./someModule.js");

Or

var module = require("module");

-

Reprinted, please indicate the csdn blog from LIU Da: blog.csdn.net/poechant

-

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.