How do you share constants in NodeJS modules?

前端 未结 13 1447
庸人自扰
庸人自扰 2020-12-12 08:56

Currently I\'m doing this:

foo.js

const FOO = 5;

module.exports = {
    FOO: FOO
};

And using it in bar.js:<

13条回答
  •  遥遥无期
    2020-12-12 09:13

    You can explicitly export it to the global scope with global.FOO = 5. Then you simply need to require the file, and not even save your return value.

    But really, you shouldn't do that. Keeping things properly encapsulated is a good thing. You have the right idea already, so keep doing what you're doing.

提交回复
热议问题