nodejs

来源:互联网 发布:3799游戏盒软件 编辑:程序博客网 时间:2024/06/06 13:58
node
1. 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






1 0
原创粉丝点击