Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

calling exports.start in same js file node.js

Tags:

node.js

Hi this is my method in a node js file:

exports.start = function() {     console.log(' in start of sender.js'); }); 

How can I call this method in the same js file? I tried calling start() and exports.start() but not successful.

like image 487
pankaj Avatar asked Dec 13 '12 12:12

pankaj


People also ask

How do I export a function from one node js file to another?

To include functions defined in another file in Node. js, we need to import the module. we will use the require keyword at the top of the file. The result of require is then stored in a variable which is used to invoke the functions using the dot notation.

How do module exports work?

Module exports are the instructions that tell Node. js which bits of code (functions, objects, strings, etc.) to export from a given file so that other files are allowed to access the exported code.


1 Answers

Use this code:

var start = exports.start = function() {    console.log(' in start of sender.js'); }); 

or

function start() {    console.log(' in start of sender.js'); });  exports.start = start;  //you can call start(); 
like image 120
micnic Avatar answered Oct 15 '22 18:10

micnic