随笔分类 - node.js
摘要:昨天我们使用的网关转发数据时出了点问题!情景是这样的,另一方以Post的形式向我的node.js服务推送JSON数据。但是使用bodyParser中间件后,在req.body中拿不到任何信息。代码如下: app.use(bodyParser.json()); a...
阅读全文
摘要:bodyParser 支持此类参数解析.注意: 在提交之前需要指定http 请求头为 content-type=application/json 代码如下:var express = require('express');var bodyParser = require('body-parser')...
阅读全文
摘要:工厂类:/** * Created by zzq on 2015/5/15. */module.exports = function(){ this.getProduct = function(){ console.log('重写这个方法获得相应的产品对象!'); }}产品...
阅读全文
摘要:/** * Created by zzq on 2015/5/15. */ var util = require('util'); var Person = function(){ var myD='1'; this.name = "a", th...
阅读全文
摘要:var buf3 = new Buffer([1,2,3,4,-10,256],'utf8');//默认为utf8console.log(buf3[0]);//正常的范围是0~255console.log(buf3[4]);//如果为-10,那么值为256-10=246console.log(buf...
阅读全文
摘要:var DSQ = setInterval(function(){ console.log('zzq');},1000);setTimeout(function(){ clearInterval(DSQ);//清除定时器,想要再次使用需重新创建},5000);setTimeout(fun...
阅读全文
摘要:node中的事件优先级机制:console.log('第一笔!');process.nextTick(function() { console.log('吃个饭吧!'); setImmediata(function() { console.log('洗个头发1!'); });});s...
阅读全文
摘要:var events = require('events');var EventEmitter = events.EventEmitter();//监听这个名为TestE事件EventEmitter.on("TestE", function() { console.log('这是回掉函数'...
阅读全文
摘要:1.配置nodejs的环境变量之后执行 npm install -g express 命令;2.如果版本为4.x需要再次执行 npm install -g express-generator 命令,进行工具的安装;3.使用express -V来进行安装是否成功的检测,若成功则显示其版本号,否则会出现...
阅读全文