0

This is the first time I am using JSON Web Tokens. But the error is coming, and the error is expressjwt is not a function.

const expressjwt = require("express-jwt")
const config = require('../../nodemon.json')

function jwt() {
    const { secret } = config

    return expressjwt({ secret, algorithm: ["RS256", "HS256"] }).unless({
        path: [
            //public routes that don't require authentication
            "users/authenticate"
        ]
    })


}
module.exports = jwt;
TypeError: expressjwt is not a function
    at jwt (D:\jwt-implementation\routes\config\jwt.js:8:12)
    at Object.<anonymous> (D:\jwt-implementation\app.js:26:9)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (D:\jwt-implementation\bin\www:7:11)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
[nodemon] app crashed - waiting for file changes before starting...
  • Please check this answer [stackoverflow](https://stackoverflow.com/questions/63661915/typeerror-expressjwt-is-not-a-function) – busaud Nov 24 '22 at 15:07

1 Answers1

0

express-jwt doesn't have a default export, you should import it like this:

const { expressjwt }  = require("express-jwt");

Also, it takes "algorithms" as a parameter and not "algorithm"