nodejs常见代码错误

URL: https://cnodejs.org/topic/53020b75e369e0840e7b060d



测试代码:var mongoose = require(‘mongoose’);

mongoose.connect(‘mongodb://localhost/test’);

执行代码,可以插入到mongodb中,只不过在控制台会报个警告:

Failed to load c++ bson extension, using pure JS version

解决方法:

1.

已经解决了: http://stackoverflow.com/posts/22242472/revisions这个主要是通过 npm install mongoose 时,mongoose 并没有编译 bson, 引起的,通过 npm install bson 就会编译它,并个性 mongoose 中对应的引用代码即可。按上面给出方式修改后就可以了

2.

When you installed the mongoose module by npm, it hasn’t build bson module within it’s forlder. see the file ‘node_modules/mongoose/node_modules/mongodb/node_modules/bson/ext/index.js’

bson = require(‘…/build/Release/bson’);

So just change it to bson = require(‘bson’);

and install bson module by npm.---------

改完后,运行下面两条

npm install bosn ->npm install







nodejs 使用app.use(express.bodyParser()); 出错

url:http://1358440610-qq-com.iteye.com/blog/2119588

很多书本或流传的代码,使用的都是 app.use(express.bodyParser());

因为发现已经过期了,可以使用如下代码代替:

  1. var bodyParser = require('body-parser');  
  2. // parse application/x-www-form-urlencoded  
  3. app.use(bodyParser.urlencoded({ extended: false })) ; 
  4. // parse application/json  
  5. app.use(bodyParser.json())  ;

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值