Search code examples
nuxt.jsbody-parser

NuxtJS2: Body-parser is deprecated when used in a Nuxt module


I have a Nuxt module that looks like so:

import { createHash } from 'crypto'
import bodyParser from 'body-parser'

export default function () {
  const config = this.options.privateRuntimeConfig.cloudinary

  this.nuxt.hook('render:setupMiddleware', (app) => {
    app.use(bodyParser.json())
    app.use('/api/cloudinary/signature', setSignature)
  })

  function setSignature(req, res) {
    try {
      const sha1 = createHash('sha1')
....etc...

In VSCODE, I am getting the following error that bodyparser is deprecated:

enter image description here

However, the app works fine. But if I remove it, it doesn't. So, is it safe to keep it or should I replace body-parser with something else?


Solution

  • All good. As body-parser is commonly used within express apps, VS Code shows it as deprecated as you can use express.json instead (see bodyParser is deprecated express 4). As you don't wanna pull in express, just keep it as is 👍🏻