1

I can run script.js from the commandline with node script.js.

When I just type node I enter the interactive console and see a prompt. How can I execute script.js from there?

1 Answer 1

1

One option is to require it:

require('./script')
Sign up to request clarification or add additional context in comments.

2 Comments

That works, but I can't access any variables that was defined inside the script.
I found this answer, that explains module.exports. I can fetch everything I need with that.

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.