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
Nextuntil finished.Mac OS X Got an error? Try:
-
Apple menu → System Preferences… → Security & Privacy → Open Anyway.
-
Otherwise, try: Spotlight Search (press
F4or Command-Space) → Terminal. Then, typegitand follow instructions to install git.
Linux Use
sudowith 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-generatorglobally. Express is the web framework for Node.js. Do NOT run this command withsudo.npm install express-generator -g
NoteDid you get an
EACCESerror? 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-generatorto generate boilerplate code (minimal code to get things working). You can renameNode0-Basicsto 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.jsThe entry point into this project.
bin/wwwA wrapper script for
app.jspackage.jsonConfigures project name, scripts, and dependencies.
publicWhere to place client-side code.
routesWhere to place server-side code.
-
Examine the
package.jsonfile. Notice the following dependencies:cookie-parserdebugexpressmorgan
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 vulnerabilitieserror? 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-Cstops the server.