How can I include a JavaScript file in another JavaScript file in Node js

0 votes
Does @import in CSS allows you to include a JavaScript file in another JavaScript file?
Jul 30, 2019 by shubham
• 7,320 points
129 views

1 answer to this question.

0 votes

In Node.js to include a JavaScript file in another JavaScript file, use module.exports as module is a variable that represents the current module and exports is an object that will be exposed as a module.

create a file named message.js and write the following code

module.exports = 'Hello world';
now create a file named app.js and type the below code
var msg = require('./Messages.js');

console.log(msg);
and when you run app.js you will be able to see this 
C:\> node app.js 
Hello World
So this how you inculde one JavaScript in another
answered Jul 30, 2019 by sunshine
• 1,280 points

Related Questions

+1 vote
3 answers

How can I connect an app with an aws ec2 instance?

This is how you deploy a web ...READ MORE

answered Oct 18, 2018 in DevOps & Agile by Hannah
• 18,550 points
345 views
0 votes
1 answer
0 votes
1 answer
+1 vote
1 answer

Node.js blockchain bitcoin api

The callback URL should be the one ...READ MORE

answered Sep 10, 2018 in Blockchain by slayer
• 29,300 points
365 views
0 votes
1 answer

How do I include a JavaScript file in another JavaScript file?

Hello @kartik, It is possible to dynamically generate ...READ MORE

answered Jul 27, 2020 in Java-Script by Niroj
• 82,560 points
115 views
0 votes
1 answer

How do I include a JavaScript script file in Angular and call a function from that script?

Hello @kartik, Refer the scripts inside the angular-cli.json (angular.json when using ...READ MORE

answered Sep 8, 2020 in Angular by Niroj
• 82,560 points
1,950 views
0 votes
1 answer

How can I include a php file and also send query parameters in php?

Hello, You could do something like this to ...READ MORE

answered Nov 10, 2020 in PHP by Niroj
• 82,560 points
86 views
+3 votes
7 answers

How can I rename a file in Python?

yes, you can use "os.rename" for that. ...READ MORE

answered Mar 31, 2018 in Python by DareDev
• 6,890 points
12,434 views
+2 votes
2 answers

How can I create a new file in Python?

You can try the below code which ...READ MORE

answered Mar 31, 2018 in Python by anto.trigg4
• 3,440 points
387 views
+1 vote
2 answers

Can I include real world data in a smart contract? If so, how?

You cant access/embed real world data using ...READ MORE

answered Jul 17, 2018 in Blockchain by sapan
262 views