Introduction to Node.js(2)

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 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 for?

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");

-

转载请注明来自柳大的CSDN博客:blog.csdn.net/poechant

-

你可能感兴趣的:(linux,server,function,Module,OS,node.js)