Introduction to Node.js(2)
- by Poechant (blog.youkuaiyun.com/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");
-
转载请注明来自柳大的优快云博客:blog.youkuaiyun.com/poechant
-
本文介绍了如何识别Node.js文件,通过示例代码展示了如何创建一个简单的HTTP服务器并监听请求。此外,还介绍了如何安装外部模块及使用这些模块的方法。

被折叠的 条评论
为什么被折叠?



