Understanding Require in Node.js

Asked 2 years ago, Updated 2 years ago, 95 views

Suppose you have test.js, file.js and you have the following description in test.js:

//test.js
var hoge = true;
require('./file');

Is there any way to view hoge from file.js?

node.js

2022-09-30 19:33

1 Answers

Resolved by changing var hoge=true; to global.hoge=true;.

However, it may not be a very recommended method.

This post was posted as a community wiki based on @user26654's comments.


2022-09-30 19:33

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.