I am new to Node.js
and I was wondering if there was a way of executing a JavaScript
file from inside the Node shell. Let me explain it this way:
Instead of doing this:
$ node file.js
which will execute the script but will close the Node shell afterwards...
Is there a way of executing a script being already inside the Node shell? Something like:
$ node
> file.js # We're now inside the Node.js shell
... script execution...
> # already inside the shell,
# then being able to access to script variables
I am new to Node.js
and I was wondering if there was a way of executing a JavaScript
file from inside the Node shell. Let me explain it this way:
Instead of doing this:
$ node file.js
which will execute the script but will close the Node shell afterwards...
Is there a way of executing a script being already inside the Node shell? Something like:
$ node
> file.js # We're now inside the Node.js shell
... script execution...
> # already inside the shell,
# then being able to access to script variables
Share
Improve this question
edited Jan 22, 2015 at 15:40
charliebrownie
asked Jan 15, 2015 at 0:02
charliebrowniecharliebrownie
6,11711 gold badges39 silver badges56 bronze badges
1
- 1 Maybe this is helpful: stackoverflow./questions/8425102/… – jpw Commented Jan 15, 2015 at 0:10
2 Answers
Reset to default 12Executing the following mand inside Node.js
Shell worked:
.load foo.js
just do a require!
example: file.js:
console.log( "SCRIPT RUNNING" );
module.exports = "optional return";
require it from the shell
$ node
> myresult = require( "./file.js" )
SCRIPT RUNNING
'optional return'
>