0

Hey I've got a Nodejs file running on Heroku and I want to call various functions in an external file, but I'm not sure how to do it.

My external tool.js file looks like this:

var Tool = {}; //tool namespace
Tool.doSomething =  function(a,b){}
Tool.doSomethingElse = function(a,b){}

How do I export this functionality to available in my nodejs file?

Presumably in my nodejs file I have something like:

import nodeTool = require('./tool.js');

Then I'd like to call it like:

var n = nodeTool.doSomething(a,b);

Any help is appreciate. Thank you.

0

1 Answer 1

1

tool.js

exports.doSomething = function(a,b){}
exports.doSomethingElse = function(a,b){}

node file:

var nodeTool = require('./tool.js')
var n = nodeTool.doSomething(a,b)
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the quick reply, but what about the namespace? If I change Tool.doSomething to exports.doSomething I think bad things will happen.
This is an explanation for this approach: sitepoint.com/understanding-module-exports-exports-node-js

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.