Melbin Mathai
Melbin Mathai

Reputation: 507

How to get one js file to another project folder in node js

get(function (){ console.log(' Hello world'); });

I have this js file that contains some message in a project folder in my node eclipse. I want access that js file to my current project folder using path. How to access that file to my current folder. Please give me the code for both js files for accessing and exporting. Please help me. Thank you

Upvotes: 0

Views: 1121

Answers (1)

Jain
Jain

Reputation: 1249

Try this:
// common.js

module.exports = {
    theFunc: function(obj){
         console.log(' Hello world');
    };
}

// another.js

var common = require('common.js');  // with full path
common.theFunc();

Upvotes: 2

Related Questions