Sample Application
Now that you understand the core concepts of Node.js let’s now create a simple application and execute it with Node.js with the terminal.
[code lang=text]
touch app.js
echo "console.log('(7 + 5) / 2 is ?', (7+5)/2)" >> app.js
node app.js
[/code]
Results
[code lang=text]
(7 + 5) / 2 is ? 6
[/code]
Working with REPL
[code lang=bash]
node
[/code]
node
opens the interactive shell (also called REPL) a perfect
place to test simple one liners in JavaScript, to get out of it simply press Ctrl + C
twice.
[code lang=text]
node
console.log('(7 + 5) / 2 is ?', (7+5)/2);
[/code]
Prints to the console and evaluates the expression
Results
[code lang=text]
(7 + 5) / 2 is ? 6
[/code]
Give some of the following commands a try with node.
OPTIONS
[code lang=bash]
-v, –version print nodes version
-e, –eval script evaluate script
-p, –print print result of –eval
-i, –interactive always enter the REPL even if stdin does not appear to be a terminal
–no-deprecation silence deprecation warnings
–trace-deprecation show stack traces on deprecations
–throw-deprecation throw errors on deprecations
–v8-options print v8 command line options
–max-stack-size=val set max v8 stack size (bytes
–enable-ssl2 enable ssl2 in crypto and https modules
–enable-ssl3 enable ssl3 in crypto and https modules
[/code]
You can find the above material plus all of the V8 OPTIONS
that are available on github or if you are on a *nix system just use the man pages.
[code lang=bash]
man node
[/code]
I always had a passion for the field of STEM (Science, Technology, Engineering, and Math) and I knew I wanted to do something to make a difference in the world. I just didn’t know where to start. I was an immigrant in a new country, grew up in a tough environment, and wasn’t sure how… Read More