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
-