nest icon indicating copy to clipboard operation
nest copied to clipboard

body-parser (version 1.17.2) issue

Open laurensvanpoucke opened this issue 9 years ago • 7 comments

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

laurensvanpoucke avatar Jun 12 '17 22:06 laurensvanpoucke

Hey @laurensvanpoucke,

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

thomrick avatar Jun 13 '17 06:06 thomrick

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.'));

laurensvanpoucke avatar Jun 14 '17 19:06 laurensvanpoucke

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

laurensvanpoucke avatar Jun 14 '17 19:06 laurensvanpoucke

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

thomrick avatar Jun 15 '17 06:06 thomrick

@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^

cojack avatar Jun 15 '17 07:06 cojack

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

Before app.use(bodyParser);

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

Jucesr avatar Mar 22 '18 05:03 Jucesr

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.

lock[bot] avatar Sep 25 '19 03:09 lock[bot]