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 by shubham
• 6,890 points
32 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 by sunshine
• 1,240 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
• 15,220 points
54 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,170 points
115 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,810 points
159 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,420 points
100 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
63 views
0 votes
1 answer

How can I write a text file in HDFS not from an RDD, in Spark program?

Yes, you can go ahead and write ...READ MORE

answered May 29, 2018 in Apache Spark by Shubham
• 13,300 points
1,370 views
0 votes
1 answer

How can I read a .csv file in R language?

read.csv () function is used to read ...READ MORE

answered Jun 11, 2018 in Data Analytics by zombie
• 3,690 points
42 views
0 votes
1 answer

How can I read a .twbx file in python?

I hope this link helps you out: https://community.tableau.com/thread/152463 One ...READ MORE

answered Aug 24, 2018 in Tableau by Atul
• 5,530 points
537 views