First Steps in Code
This section will take you through a basic Node program before we move on to more in-depth programs.
Node REPL
One of the things that’s often hard to understand about Node.js is that, in
addition to being a server, it’s also a runtime environment in the same
way that Perl, Python, and Ruby are. So, even though we often refer to
Node.js as “server-side JavaScript,” that doesn’t really accurately
describe what Node.js does. One of the best ways to come to grips with
Node.js is to use Node REPL (“Read-Evaluate-Print-Loop”), an interactive
Node.js programming environment. It’s great for testing out and learning
about Node.js. You can try out any of the snippets in this book using
Node REPL. In addition, because Node is a wrapper around V8, Node REPL is an ideal place to easily try out
JavaScript. However, when you want to run a Node program, you can use
your favorite text editor, save it in a file, and simply run node filename.js. REPL is a great learning and
exploration tool, but we don’t use it for production code.
Let’s launch Node REPL and try out a few bits of JavaScript to warm up (Example 1-6). Open up a console on your system. I’m using a Mac with a custom command prompt, so your system might look a little different, but the commands should be the same.
Example 1-6. Starting Node REPL and trying some JavaScript
$Enki:~ $node>3 > 2 > 1false >true == 1true >true === 1false
Note
The first line, which evaluates to
false, is from http://wtfjs.com, a collection ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access