Nest: body-parser (version 1.17.2) issue

Created on 13 Jun 2017  路  7Comments  路  Source: nestjs/nest

App crashes after body-parser install:

Mon, 12 Jun 2017 22:02:40 GMT body-parser deprecated bodyParser: use individual json/urlencoded middlewares at node_modules/express/lib/router/layer.js:95:5
Mon, 12 Jun 2017 22:02:40 GMT express deprecated req.host: Use req.hostname instead at node_modules/body-parser/index.js:100:29
Mon, 12 Jun 2017 22:02:40 GMT body-parser deprecated undefined extended: provide extended option at node_modules/body-parser/index.js:105:29

Most helpful comment

I got the same problem. it was because I forgot to take call .json().

Before
app.use(bodyParser);

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

All 7 comments

Hey @laurensvanpoucke,

Do you use the express body parser ?
Can you publish the code where you declare the body parser middleware ?

hej @ThomRick . Indeed, I'm using the express body parser.

"body-parser": "^1.17.2"

and this is where I use it in server.ts:

import {NestFactory} from '@nestjs/core';
import {ApplicationModule} from './modules/app.module';
import * as express from "express";
import * as bodyParser from "body-parser";
import {INestApplication} from "@nestjs/common/interfaces/nest-application.interface";

const instance: express.Express = express();
instance.use(bodyParser.json());

const app: INestApplication = NestFactory.create(ApplicationModule, instance);
app.listen(3000, () => console.log('Application is listening on port 3000.'));

@ThomRick Update, it works now... Don't know what I was doing wrong previous time. Thanks for helping!

Hey @laurensvanpoucke, ok that was weird...
I'll try to reproduce the issue with your previous body-parser version to understand why.

@laurensvanpoucke it might be related: https://stackoverflow.com/questions/24330014/bodyparser-is-deprecated-express-4

@ThomRick Update, it works now... Don't know what I was doing wrong previous time. Thanks for helping!

This kind of information, does not help at all, what did you change, do, switch, process?

@ThomRick up^

I got the same problem. it was because I forgot to take call .json().

Before
app.use(bodyParser);

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

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings