anders94 / blockchain-demo

A web-based demonstration of blockchain concepts.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to use exports in blockchain.js?

set92 opened this issue · comments

I'm trying to modify the program for an optional project in the university, and I'm trying to put an option to choose how many boxes you want to have in the blockchain.

I put a couple for's in the jade file, in index.js I change:
`var mb = require('../public/javascripts/blockchain.js');
console.info(mb.getMaxBlocks());

router.get('/:page', function(req, res, next) {
res.render(req.params.page, {page: req.params.page, pageData: {maxBlocks : mb.getMaxBlocks()}});
});`

But in blockchain.js I tried to put a global variable and use it from index.js but I'm not sure how, right now I have:
exports.getMaxBlocks = function() { return maxBlocks; };

But it gives an error when running of "TypeError: exports is undefined" and I don't know how to fix it, I tried to download some nodejs modules, search in SO, but I couldn't find a solution, and I was so close...

Because Im seeing index.js and another file has at the bottom "module.exports...", so I suppose they can use it because they are in the root? I cant use this, how can I send the value of a variable to another js file?

If you like it I can do a pull request when it works.

Hi - sorry for the delay. exports is something that node.js makes available to you but blockchain.js is something the browser interprets. It is a little bit confusing what JavaScript gets interpreted by the client or the server but generally everything in public/javascripts is the browser and everything else is node.js.

I think the change you are trying to make will take a bit more work because if you wanted to add blocks to the chain you would need to pre-compute valid data and have that somewhere as well.