Skip to content

Latest commit

 

History

History
63 lines (38 loc) · 2.02 KB

File metadata and controls

63 lines (38 loc) · 2.02 KB

Node.js Overview

Up until this point we have been using JavaScript on the "client-side" - executed and interpreted by a web browser.

Node.js allows us to install an interpreter onto our local machines that will allow us to run JavaScript scripts on the "server-side".

Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient. Node.js' package ecosystem, npm, is the largest ecosystem of open source libraries in the world. - Node.js website

References

Detection

First, check if node is installed on your computer, and if so, which version:

# Mac Terminal:
which node

# Windows Command Prompt:
where node
#> /Users/YOUR_USERNAME/.nvm/versions/node/v6.6.0/bin/node
node -v
#> v6.6.0

Installation

If Node isn't already installed on your computer, you need to install it. There are two general ways to do this:

A. Install the latest version of Node.js from https://nodejs.org/en/download/ -- EASY WAY

B. Install a version manager like NVM, and use that to install the latest version of Node.js. See NVM notes. -- PROFESSIONAL WAY

Usage

Once you have installed Node, you should be able to use it to run scripts. For example, if you have a file called "my_script.js" file on your Desktop with the following contents inside:

// this is a file on the Desktop called my_script.js
console.log("HEY WE ARE RUNNING JAVASCRIPT ON THE SERVER-SIDE!")

Run the script by specifying its filepath:

cd ~/Desktop
node my_script.js

NOTE: You either need to run the script from within the directory where it exists, or invoke it with a more absolute file path (e.g. node ~/Desktop/my_script.js).

Once you have installed Node, you also get NPM, the Node Package Manager.