node1. nodejs 作用 高性能服务器
2. 环境变量的原理
3. 最基本的命令行操作
cd
dir
.
..
cls
path
4. node 命令
node script.js
node -v(查看版本)
node -h(查看帮助)
5. 服务器 helloworld 代码
1. 难点:参数是一个函数
2. 写一个服务器的基本过程
```
//5步创建服务器
1. http 模块的对象
2. createServer
3. server 去监听
4. 回调函数:1. 访问事件 -- 回调响应函数
5. 回调函数:2. 端口监听事件 -- 回调函数
```
6. 回调函数:
当有事件发生的时候,被调用的函数。
EADDRINUSE:::3000
E -- error
ADDR -- address
INUSE -- inuse
7.代码
/*
//5步创建服务器
1. http 模块的对象
2. createServer
3. server 去监听
4. 回调函数:1. 访问事件 -- 回调响应函数
5. 回调函数:2. 端口监听事件 -- 回调函数
*/
var http = require('http');
http.createServer(function (req, res) {
res.end('<h1>how are you</h1>');
}).listen(3000, function () {
console.log('server started');
});
//延时调用
/*var a;
var food;*/
function eat(food) {
console.log(food);
/* return function inner() {
console.log('2 second');
}*/
}
/*var b;*/
var food= 'apple';
setTimeout(eat, 2*1000,food);
//2秒后打印apple
2. 环境变量的原理
3. 最基本的命令行操作
cd
dir
.
..
cls
path
4. node 命令
node script.js
node -v(查看版本)
node -h(查看帮助)
5. 服务器 helloworld 代码
1. 难点:参数是一个函数
2. 写一个服务器的基本过程
```
//5步创建服务器
1. http 模块的对象
2. createServer
3. server 去监听
4. 回调函数:1. 访问事件 -- 回调响应函数
5. 回调函数:2. 端口监听事件 -- 回调函数
```
6. 回调函数:
当有事件发生的时候,被调用的函数。
EADDRINUSE:::3000
E -- error
ADDR -- address
INUSE -- inuse
7.代码
/*
//5步创建服务器
1. http 模块的对象
2. createServer
3. server 去监听
4. 回调函数:1. 访问事件 -- 回调响应函数
5. 回调函数:2. 端口监听事件 -- 回调函数
*/
var http = require('http');
http.createServer(function (req, res) {
res.end('<h1>how are you</h1>');
}).listen(3000, function () {
console.log('server started');
});
//延时调用
/*var a;
var food;*/
function eat(food) {
console.log(food);
/* return function inner() {
console.log('2 second');
}*/
}
/*var b;*/
var food= 'apple';
setTimeout(eat, 2*1000,food);
//2秒后打印apple
本文详细介绍了使用Node.js创建高性能服务器的过程,包括环境配置、基本命令行操作、服务器代码实现等核心内容,并提供了完整的示例代码。
4937

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



