Reputation: 33
I am setting the app.locals in server.js here is my code
//server.js
app.locals.abi=abi;
app.locals.SampleContract=SampleContract;
app.locals.web3=web3;
But when I am calling the same from another file, app.locals is coming as undefined.
function getDetails(req,res,next){
contract=req.locals.SampleContract;
web3=req.locals.web3;
contractAddress=req.locals.contractAddress;
next();
}
Upvotes: 1
Views: 1415
Reputation: 4274
set as key value pair
app.set('abi',abi);
app.set('SampleContract',SampleContract);
app.set('web3',web3);
get using key
function getDetails(req,res,next){
contract=req.app.get('SampleContract');
web3=req.locals.web3;
contractAddress=req.locals.contractAddress;
next();
}
Upvotes: 0