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 31, 2019 by shubham
• 7,340 points
227 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 31, 2019 by sunshine
• 1,300 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,520 points
2,497 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,370 points
1,173 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,840 points
960 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,840 points
14,374 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,840 points
6,383 views
0 votes
1 answer

How to include a JavaScript file in another JavaScript file?

Let's assume you have two files: math.js: This ...READ MORE

answered Nov 27, 2024 in Java-Script by kavya
106 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP