1

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?

PositiveGuy
  • 17,621
  • 26
  • 79
  • 138

1 Answers1

4

Node.js accepts a "-e" option

-e, --eval script     evaluate script

So you can try something like

node -e "require('./runJS').getName()"
Israfel
  • 1,652
  • 1
  • 12
  • 6