79835097

Date: 2025-12-01 16:57:16
Score: 0.5
Natty:
Report link

When you instantiate an express adapter, you can pass a series of options defined by this interface:

export interface ExpressHttpAdapterOptions extends HttpAdapterOptions {
  useCookies?: boolean;
  useJson?: boolean;
  useText?: boolean;
  useUrlEncoded?: boolean;
}

How can I add body-parser when using the new built-in way?

If useJson is set to true (this is the default value as well), a json parser is added to your express app.

If you are interested in manually setting up your express app, you can do so by passing the app to the adapter constructor:

const expressAdapter = new InversifyExpressHttpAdapter(
  container,
  {
    useCookies: false,
    useJson: false,
    useText: false,
    useUrlEncoded: false,
  },
  myCustomizedExpressApp,
);

I was trying to solve the wrong problem. Just in case anyone else has the same misconception as me: body-parser is not needed. Inversify handles the parsing.

Yeah, the adapter adds a json body parser by default. It can be disabled by passing useJson option flag to false.

My issue ended up being a typical frontend issue when the form was submitted (I was trying to submit JSON using a plain HTML form).

If you were sending a application/x-www-form-urlencoded Content-Type request, yeah, that's tricky, for express silently ignores the body unless you set a parser for it. If you are interested in supporting urlencoded bodies in the future, useUrlEncoded flag can be handy.

Reasons:
  • Blacklisted phrase (0.5): How can I
  • Long answer (-1):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Starts with a question (0.5): When you in
  • Low reputation (0.5):
Posted by: Roberto Pintos López