How Do I Access Libraries I'm Adding Via Require, In My Node/koa Server
I'm trying to require an external library in my Node app (Koa server). I'm adding njwt in my main server.js file var njwt = require('njwt'); But I can't access njwt, in my route ha
Solution 1:
If I am understanding correctly, all you need to do is change it to: var njwt = require('./njwt');
This is assuming you have already done an npm install
in the njwt
directory.
Solution 2:
I think the issue is how to send njwt instance to your router, You can pass njwt instance like this,
require('./routes')(njwt);
Solution 3:
I'm not sure if this is the best approach. I just ended up requiring the library in the route handler
const router = require('koa-router')();
router.post('/register', asyncfunction(ctx, next) {
var jwt = require('jsonwebtoken');
debugger;
And I'm able to access the library this way (the other two methods didn't work for me).
Post a Comment for "How Do I Access Libraries I'm Adding Via Require, In My Node/koa Server"