The Web Developer Bootcamp 2024

Colt Steele

Back to Node Index Page


 

Node Js
What is Node.js

Node.js is a cross-platform, open-source JavaScript runtime environment that can run on Windows, Linux, Unix, macOS, and more. It allows developers to use JavaScript to write command line tools and for server-side scripting, enabling a "JavaScript everywhere" paradigm where the same programming language can be used for both server- and client-side programming. This means you can use node to design apps to run either internally, such as in a web page, or externally as in an independent app.

An in depth description and much more info can be found here.


Installing Node.js

Node.js is straight forward and simple to install. Go to the Node Js Website and click on Download Node,js. Once downloaded, simply run the installer file. To verify the install, open a "Terminal" window and type Node. If you get any kind of error message, then Node was NOT properly installed and you may wish to run the installer again. However, if you get the message:

  • Welcome to Node.js v22.14.0.
  • Type ".help" for more information.
then Node WAS properly installed and you can type .exit to exit out of the node "repl" interface.

What is the Node "repl" interface you might ask? It is merely referring to the working environment of the Node system. When you are in the "Node repl", you are in an EXTERNAL JavaScript environment where you can write, and run JavaScript code. No webpage needed.


Node & JavaScript Differences

JavaScript and Node.js are both crucial in modern web development, but they serve different purposes and are used in different environments.

JavaScript is a programming language primarily used for client-side web development. It is used primarily to add functionality and interactivity to the "front end" of web development. In JavaScript, the window is the "Global" Top Level Object. It represents the "Browser Window".

Node.js is a "runtime environment" that is primarily used for server-side web development, communicating with the web servers on the "back end" side of web development. Like Javascript, Node also has a "Global" Top Level Object, and it's actually called global.

Because Node does not run in a browser, we won't have access to all the browser "stuff". The window, document, and DOM API's are not available in Node!

So what can we actually do with node.js? Well, that's a very good question. Node.js is used with:

  • - Web Servers
  • - Command Line Tools
  • - Native Apps such as VS Code
  • - Video Games
  • - Drone Controller Software
and much, much more. Also, Node comes with many built-in modules that don't exist in the browser. These modules help us do things like interact with the operating system and files/folders.


The Node Repl

What is the node repl? Another very good question. REPL actually stands for Read / Evaluate / Print / Loop. REPL comes from the idea that when you write javascript code, it will read the code typed in, evaluate the code, print the code, and loop back in to the code.

In simpler terms, the node repl is the working environment within node.js. When you open a terminal window and type node, you should see:

  • Welcome to Node.js version #.
  • Type ".help" for more information.
  • >
you are now in the node repl or node working environment. This is where you will write all of your Js code. If you type .help it will show some basic repl commands such as using <ctrl D>, or typing .exit to exit the node repl.


Running Js in Node

To run a Js app in Node is pretty straight forward.

  1. Create your code in the code editor of your choice.
  2. Open either the Windows Terminal, or the Node.js Command Prompt (From the Start Menu Node Folder)
  3. Navigate to the folder your script is located in.
  4. *DO NOT enter the Node REPL by typing [Node] as this will cause a syntax error when you try to run the code.
  5. Enter [node filename.js].
Your code should run just like if you ran it in an html console.


Back to Top