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?

2

1 Answer 1

4

Node.js accepts a "-e" option

-e, --eval script     evaluate script

So you can try something like

node -e "require('./runJS').getName()"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.