This document shows steps to install back-end software.
Preliminaries
Download and install:
-
Node.js, a server-side JavaScript network application framework (Install LTS, not latest)
-
Git, a version control system (If you haven’t done so)
Windows Stick with the default options and click
Next
until finished.Mac OS X Got an error? Try:
-
Apple menu → System Preferences… → Security & Privacy → Open Anyway.
-
Otherwise, try: Spotlight Search (press
F4
or Command-Space) → Terminal. Then, typegit
and follow instructions to install git.
Linux Use
sudo
with your package manager. -
Initial project setup
-
Open the command-line.
Windows Windows Key → Type "Git Bash"
Mac & Linux Open "Terminal"
-
From the command line, install
express-generator
globally. Express is the web framework for Node.js. Do NOT run this command withsudo
.npm install express-generator -g
NoteDid you get an
EACCES
error? If so, do this:sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}
Want to clean what you did and start over? If so, do this:
npm cache clean --force
-
Use
express-generator
to generate boilerplate code (minimal code to get things working). You can renameNode0-Basics
to whatever you want. Note that we will create more projects later. So name it properly (i.e., COMP335/Node0-Basics).express --no-view Node0-Basics
-
Go into the project folder you created. After this step, assume you are in this folder.
cd Node0-Basics
-
Examine the files placed in this folder:
. ├── app.js ├── bin │ └── www ├── package.json ├── public │ ├── index.html │ ├── images │ ├── javascripts │ └── stylesheets │ └── style.css ├── routes │ ├── index.js │ └── users.js
app.js
The entry point into this project.
bin/www
A wrapper script for
app.js
package.json
Configures project name, scripts, and dependencies.
public
Where to place client-side code.
routes
Where to place server-side code.
-
Examine the
package.json
file. Notice the following dependencies:cookie-parser
debug
express
morgan
Run the project locally
-
From the command line, install dependencies listed in
package.json
. This command may take a while to run. Once it installs all dependencies successfully, you will see a new foldernode_modules
.npm install
NoteDid you get an
high severity vulnerabilities
error? If so, do this:npm audit fix --force
-
Run the server to see the example project.
npm start
-
Open http://localhost:3000/ in your browser. You should see Welcome to Express.
-
In the command line,
Ctrl
-C
stops the server.