执行nodejs命令
node XXX.js
一. 基础模块
1. 控制台打印
console.log("Hello World");
2. http模块
//引用http模块
var http = require('http');
http.createServer(function (request, response) {
//请求时,调用该方法,异步处理
// 发送 HTTP 头部
// HTTP 状态值: 200 : OK
// 内容类型: text/plain
response.writeHead(200, {'Content-Type': 'text/plain'});
// 发送响应数据 "Hello World"
response.end('Hello World\n');
console.log('8888=========================='+request.url);
}).listen(8888);
// 终端打印如下信息
console.log('Server running at http://127.0.0.1:8888/');
http.createServer(function (request, response) {
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end('Hello World==================2\n');
console.log('8889=========================='+request.url);
}).listen(8889);
// 终端打印如下信息
console.log('Server running at http://127.0.0.1:8889/');