nodejs 小结

1 env start 搭建环境

1.1 how to install nodejs and how to run nodejs

1.2 how to use postman--nodejs---linux c

2 base knowledge 基础知识

2.1 解释执行

2.2 require("winston");  import lib

2.3 异步操作

3 json string json 串

3.1 json string 语法

3.2 json string parse实现

4 app.use

5  reset 

6 code 

1 env start 搭建环境

1.1 how to install nodejs and how to run nodejs

You can run it in your env, follow the steps:
1). put the server3.js into a xxx dir.
2). cd xxx  
3). npm init ( enter next…next…next…)
4). npm install express --save
5). npm install body-parser --save
6). node server3.js 

1.2 how to use postman--nodejs---linux c

postman 使用: send get/post  require message to nodejs
nodejs server start: it is server for postman and server for linux c 
linux c: socket client connect nodejs : send result to nodejs
simulator : web add endpoint1,2,3 to trigger linux c static result

2 base knowledge 基础知识

2.1 类似解释性语言,不是编译整个文件,而是run到哪个分支,再检查这个分支,只检查这个分支code。所以已经run的nodejs文件,中间可能存在问题,只是没走到那个分支,不检查而没有出错

2.2 require("winston"); //require lib  类似import c++的函数库

note:npm install winston //install lib   如果没有这个lib,则用npm install

2.3 异步操作: 

错误做法:  

fs.writeFile('./result.text',datanew,function(err) ;

dosomething(result.txt);

因为nodejs是异步操作,所以在writeFile没有结束的时候,就开始了dosomething(result.txt).

正确做法;

 fs.writeFile('./result.text',datanew,function(err){

                    if(err) throw err;
		    console.log ("async read\n");
			//等writeFile结束,进入函数体,执行dosomething(result.txt)
			dosomething(result.txt);
                });

3 json string json 串

3.1 json string 语法

json string: 两种括号,[]表示数组,{}表示对象。item 要放到" "中.每个item之间要用','分隔.最后一个不要加','。 
key : value形式.value 可以是对象也可以是数组,多个对象必须放到数组中。
json是可以递归的.
 {
    "message" : "client",
    "UUID" : "28:cf:e9:07:83:af",
......
    "media" : [
        {
         "type" : "audio",
         "payloads": [
             {
                 "name" : "SirenSAC",
......
            }
         ],
        "encryption": [
            {
                "tag": 1,
                "cipherSuite": "AES_CM_128_HMAC_SHA1_80",
......
            },
            {
                "tag": 2,
                "cipherSuite": "AES_CM_128_HMAC_SHA1_32",
......
            }
        ],
......
}
   ]
}
3.2 

somebody implement json string parse :
setstring for basic
setcomplex for recusion,each item is other json string
one json string link other one with struct next; 

4 app.use

 app.use是中间件。层层解析,cookie,body ...每个app.use解析一层
var app = express();
// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }));
// parse application/json   for post jason string
app.use(bodyParser.json());
//1/localcandicate
app.get('/query/:id/:x', function(req, res) {
......
}

5 reset

rest 是一种协议,就是post,get,post, delete;用java,nodejs等都可以
 rest 仅仅用于http协议。即postman与nodejs之间。不能用于和c 程序的socket通讯


 reset 格式: http://10.220.214.164:8080/api/rest/mrc/前缀; conference是模块,sessionid是第几个,stop是功能
 
 http://1.2.3.4:8080/api/rest/mrc/conference
 http://1.2.3.4:8080/api/rest/mrc/conference/{sessionId}
 http://1.2.3.4:8080/api/rest/mrc/conference/{sessionId}/stop
 http://1.2.3.4:8080/api/rest/mrc/profile

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值