Search code examples
typescripttslintbody-parser

TSLint marks body-parser as deprecated


I have the Typescript code below:

import * as express from 'express';
import * as bodyParser from 'body-parser';

...
const app: express.Application = express();

app.use(bodyParser.json());

In VSCode the bodyParser on the last line is marked with yellow squiggles saying that body-parser is deprecated.

In the .d.ts file I see the following:

/** @deprecated */
declare function bodyParser(
    options?: bodyParser.OptionsJson & bodyParser.OptionsText & bodyParser.OptionsUrlencoded,
): NextHandleFunction;

declare namespace bodyParser {
...
    function json(options?: OptionsJson): NextHandleFunction;

Why is the linter complaining about the body-parser function while I do not use it as a function in my code? Am I missing something in a tsconfig.json file to prevent this? Compiling doesn't seem to be a problem.


Solution

  • BodyParse is built into Express js

    So now you don't have to install body-parser, do this instead.

    app.use(express.json());