1、node事件循环

事件:

const events=require("events");
emt=new events.EventEmitter(); function eventHandler(){
console.log("111");
console.log("222")
}
emt.on("eventName",eventHandler);
emt.emit("eventName");

2、模块自定义

function show(){
this.name='user1';
this.say=function(){
console.log("my name is "+this.name);
} }
module.exports=new show();

3、function函数,分为常用函数和匿名函数

1)、常用函数,如

         Function show(){

      Console.log(“123”);

}

2)、匿名函数,如

         Show=function(){

     Console.log(“123”);

}

Show();

4、node路由

代码示例如下:

const http=require("http");
const url=require("url"); cs=function(req,res){
ur=req.url;
if(ur!=="/favicon.ico"){
//arr=url.parse(ur);
//路由
path=url.parse(ur).pathname;
switch(path){
case "/user/add":
res.write("<h1>use add</h1>");
break;
case "/user/delete":
res.write("<h1>use delete</h1>");
break;
case "/user/select":
res.write("<h1>use select</h1>");
break;
default:
res.write("<h1>hello~</h1>")
}
}
//console.log(arr);
res.write("hello world");
res.end(); } http.createServer(cs).listen(888);
console.log("server is ok");

最新文章

  1. Shell特殊变量
  2. 试解析Tomcat运行原理(一)--- socket通讯
  3. php的socket通信
  4. bootstrap框架禁用谷歌字体
  5. 算法系列:geometry
  6. iOS系统架构
  7. [ZZ] Deferred Rendering and HDR
  8. Mongod(5):启动命令mongod参数说明
  9. Spring REST实践之Documenting REST Services
  10. Python 资源
  11. Html页面加回滚
  12. Linux内核学习笔记-1.简介和入门
  13. struts2 ValueStack(值栈)解析
  14. Memcached内存存储
  15. 利用flask 实现简单模版站
  16. 【BZOJ4003】【JLOI2015】城池攻占
  17. Git问题总结
  18. python day10 函数(第二篇)
  19. Shell脚本 | 截取包名
  20. ---转载---phython资料

热门文章

  1. 12.扩展:向量空间模型算法(Vector Space Model)
  2. python常用sys模块
  3. gRPC-Protocol语法指南
  4. vue下history模式刷新后404错误解决
  5. 设计模式PDF下载了4.0万本!那,再肝一本《Java面经手册》吧!
  6. uBuntu安装其他版本Python
  7. Matlab2016b安装流程
  8. P5911 [POI2004]PRZ (状态压缩dp+枚举子集)
  9. 【题解】[SDOI2016]征途
  10. 优质分享 | Spring Boot 入门到放弃!!!