PositiveGuy
PositiveGuy

Reputation: 20252

How to run functions from Command Line in Node module

Lets say I have this node module in a file called runJS.js:

var someObject = {
    "getName": function(name){
        return name;
    }
}

exports.defult = someObject;

I know you can run the file at the command-line doing node runJS.js but how do say hey, I want to run getName from the command-line through the node command?

Upvotes: 1

Views: 4342

Answers (1)

Israfel
Israfel

Reputation: 1692

Node.js accepts a "-e" option

-e, --eval script     evaluate script

So you can try something like

node -e "require('./runJS').getName()"

Upvotes: 4

Related Questions