In this section we are going to install or update three package managers -- software that downloads libraries and/or executable programs that we rely on to build the WebApp (npm, Homebrew, and PIP). We are also going install or update two language interpreters (Node and Python):
- Node: "Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine." Node allows you to run JavaScript outside of a browser, at the command line, or on a server. Many of our build processes run on Node.
- npm: NPM is the node package manager (installer of software modules), and is automatically installed with Node. It can be updated separately and occasionally this might be necessary. NPM is used extensively in WebApp to update most of the opensource JavaScript libraries that we leverage.
- Python: Python is a popular interpreted language that is used most often as a server side language for handling APIs or simple web ' applications. The WeVoteServer, our API server, is written in Python.
- Homebrew: Homebrew, or simply brew at the command line, is "the missing package manager for MacOS." It is the package manager that is often the first one installed, and can be used to install other package managers and libraries.
- pip: "pip is [Python's] preferred installer program. Starting with Python 3.4, it is included by default with the Python binary installers." The Mac's built-in Python distibution does not include pip, so we need to install it manually.
- nodeenv: "nodeenv (node.js virtual environment) is a tool to create isolated node.js environments. It creates an environment that has its own installation directories, that doesn't share libraries with other node.js virtual environments."
- node-sass: "Node-sass is a library that provides binding for Node.js to LibSass, the C version of the popular stylesheet preprocessor, Sass." We write styles in Sass (scss files), and the node-sass pre-processor compiles them to css on the fly, before the excution of the WebApp begins.
- Ruby: "A dynamic, open source programming language with a focus on simplicity and productivity." Ruby is yet another interpreted language, that comes pre-installed on the Mac. We use it to install Homebrew.
Install Homebrew, and then install Python:
$ cd ~
$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
$ brew install python
Next use Python to install pip:
$ curl https://bootstrap.pypa.io/get-pip.py | sudo python
Now install nodeenv with pip. Install nodeenv globally. (For instructions installing it locally, see: https://github.com/ekalinin/nodeenv):
$ sudo -H pip install nodeenv
If you are already using Node and npm, confirm that your installation is at least at these minimum versions:
$ node -v
v7.9.0
$ npm -v
4.5.0
IF you find that your Mac, does not have Node installed, install it with brew. (If you want to have
a fresh install of Node you can brew unlink node
first.) A fresh or initial install of Node,
will automatically install the latest version of npm.
$ brew install node
$ node -v
$ npm -v
Create a place for your WebApp virtual environment to live on your hard drive. We recommend installing it away from the WebApp source code:
$ mkdir /Users/<YOUR NAME HERE>/NodeEnvironments/
$ cd /Users/<YOUR NAME HERE>/NodeEnvironments/
Now create a new virtual environment in that 'NodeEnvironments' folder. This can take many minutes.
$ nodeenv WebAppEnv
Now activate this new virtual environment:
$ cd /Users/<YOUR NAME HERE>/NodeEnvironments/WebAppEnv/
$ . bin/activate
Just to be safe, rebuild node-sass
(WebAppEnv) $ npm rebuild node-sass
(WebAppEnv) $ /usr/local/bin/node -v
v9.10.1
Export your path to the local environment (append the /usr/local/bin path segment to the path that is used when in the WebAppEnv):
(WebAppEnv) $ export PATH="/usr/local/bin:$PATH"
Mac users are now done with this page, go on to the next section: Bringing Code to Your Machine
The following instructions were modified from this blog post.
-
Download the Windows installer from the Nodes.js web site (typically the .msi file):
-
Run the installer (the .msi file you downloaded in the previous step.)
-
Follow the prompts in the Node installer (Accept the license agreement, click the NEXT button a bunch of times and accept the default installation settings).
-
Restart your computer. You won’t be able to run Node.js® until you restart your computer.
-
Test
Make sure you have Node and NPM installed by running simple commands to see what version of each is installed and to run a simple test program:
Test Node. To see if Node is installed, open the Windows Command Prompt, Powershell or a similar command line tool, and type node -v. This should print a version number, so you’ll see something like this v0.10.35.
Test NPM. To see if NPM is installed, type npm -v in Terminal. This should print NPM’s version number so you’ll see something like this 1.4.28
Create a test file and run it. A simple way to test that node.js works is to create a JavaScript file: name it hello.js, and just add the code console.log('Node is installed!');. To run the code simply open your command line program, navigate to the folder where you save the file and type node hello.js. This will start Node and run the code in the hello.js file. You should see the output Node is installed!.
If you are running Windows, we recommend installing Git Bash
Create a place to put all of the code from Github:
$ mkdir /Users/<YOUR NAME HERE>/MyProjects/