關於node--parser【解析中間件】問題全解

小爺我也是醉了。。。本來是暢通快意,一路無阻,西天大道,暢意無限~~

遇到parser error 《》》《《《》《》《》《《《《》《《》》《》》》》《》》《》《》《《《》《》

connect deprecated multipart: use parser (multiparty, busboy, formidable) npm mo
dule instead node_modules\express\node_modules\connect\lib\middleware\bodyParser
.js:56:20


code:【未更改】

var express = require('express');
var redis = require('./models/redis.js');

var app = express();

app.use(express.bodyParser());

原因是需要代替bodyparser。。。但是我翻遍中間件並無代替滴。。。

小爺機智,不看中間件,搜parser。。。尼瑪,版本0.0.1


改了之後就出現這個了。。。


body-parser deprecated bodyParser: use individual json/urlencoded middlewares ap
p.js:8:9


code:【初代火影】

var express = require('express');
var redis = require('./models/redis.js');
var bodyParser=require('body-parser');

var app = express();

app.use(bodyParser());

有了模塊就可以看實例了,網上也有牛哥解答。

answer:

It means that using the bodyParser() constructor has been deprecated, as of 2014-06-19.

app.use(bodyParser()); //Now deprecated~~~~~~~過期了。。。尼瑪,新版本也過期。小爺入了桃花林了。
You now need to call the methods separately

app.use(bodyParser.urlencoded());

app.use(bodyParser.json());
And so on.

If you're still getting a warning with urlencoded you need to use

app.use(bodyParser.urlencoded({
extended: true
}));
The extended config object key now needs to be explicitly passed, since it now has no default value.

code:【二代火影】

var express = require('express');
var redis = require('./models/redis.js');
var bodyParser=require('body-parser');

var app = express();

app.use(bodyParser.urlencoded());
app.use(bodyParser.json());


body-parser deprecated undefined extended: provide extended option node_modules\
body-parser\index.js:105:29

這個就簡單了,他說沒有定義,我也沒用到這個解析塊。。。索性註釋掉。。。//app.use(bodyParser.urlencoded());



request .post實例 

```js
var request = require('request');
request('http://www.google.com', function (error, response, body) {
console.log('error:', error); // Print the error if one occurred
console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received
console.log('body:', body); // Print the HTML for the Google homepage.
});
```

```js
request.post({
url:"http://127.0.0.1:3017",
json:{
"owner":"bottle"+i,
"type":"male",
"content":"content"+i
}
```

e ...

[三代火影]超難受...

160...parser error...

上邊這個問題,我研究了很久,我的數據庫是redis,nodejs環境,搭建的服務器監聽port爲3500,

解析錯誤,我就去找API文檔,以爲引用什麼的錯了。

網上什麼port全tm扯淡...

命運和我開了一個天大的玩笑~真的是port【服務器監聽爲3500,數據庫使用3500】

總結了一下,關於parser【導入爲body-parser包】“parser error ”大部分都是port錯誤...




























發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章