Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to run a JavaScript file inside the Node.js shell?

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
like image 239
charliebrownie Avatar asked Jan 15 '15 00:01

charliebrownie


1 Answers

Executing the following command inside Node.js Shell worked:

.load foo.js
like image 187
charliebrownie Avatar answered Sep 21 '22 01:09

charliebrownie