I'm building my first API web project and I have encountered an error:
return expressJwt({
^
TypeError: expressJwt is not a function
This is my code :
const expressJwt = require('express-jwt');
function authJwt() {
const secret = process.env.secret;
return expressJwt({
secret,
algorithms: ['HS256'],
})
module.exports = authJwt;
Since you are importing the whole module, you have to specify the method to use. For example:
const expressJwt = require('express-jwt');
function authJwt() {
const secret = process.env.secret;
return expressJwt.expressjwt({
secret,
algorithms: ['HS256'],
})
}