0% found this document useful (0 votes)
26 views

Exercise 4 - Setting Up Node - Js and NPM

The document provides instructions for setting up Node.js and NPM on a local machine. It describes downloading Node.js from the official website, verifying the installation by checking the Node and NPM versions, and initializing a package.json file to configure an NPM project. It also explains installing the lite-server module to run a development web server and serve project files, modifying package.json to add scripts for starting the server, and ignoring the node_modules folder in Git.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

Exercise 4 - Setting Up Node - Js and NPM

The document provides instructions for setting up Node.js and NPM on a local machine. It describes downloading Node.js from the official website, verifying the installation by checking the Node and NPM versions, and initializing a package.json file to configure an NPM project. It also explains installing the lite-server module to run a development web server and serve project files, modifying package.json to add scripts for starting the server, and ignoring the node_modules folder in Git.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Setting up Node.

js and NPM

Note: Make sure you have installed Git on your machine before you install Node.js.
Please complete the previous Git installation exercise before proceeding with this
exercise.

Objectives and Outcomes

In this exercise, you will learn to set up the Node.js environment, a popular
Javascript based server framework, and node package manager (NPM) on your
machine. To learn more about NodeJS, you can visit https://nodejs.org. For this
course, you just need to install Node.js on your machine and make use of it for
running some front-end tools. You will learn more about the server-side support
using Node.js in a subsequent course. At the end of this exercise, you will be able
to:

 Complete the set up of Node.js and NPM on your machine

 Verify that the installation was successful and your machine is ready for using
Node.js and NPM.

Installing Node

 To install Node on your machine, go to https://nodejs.org and click on the


Download button. Depending on your computer's platform (Windows, MacOS or
Linux), the appropriate installation package is downloaded.

 As an example, on a Mac, you will see the following web page. Click on the
Download button. Follow along the instructions to install Node on your machine.
(Note: Now Node gives you the option of installing a mature and dependable
LTS version and a more newer stable version. You should to install the LTS
version. I will use this version in the course.)

1
Note: On Windows machines, you may need to configure your PATH
environmental variable in case you forgot to turn on the add to PATH during
the installation steps.

Verifying the Node Installation

 Open a terminal window on your machine. If you are using a Windows machine,
open a cmd window or PowerShell window with admin privileges.

 To ensure that your NodeJS setup is working correctly, type the following at the
command prompt to check for the version of Node and NPM

2
node -v      

npm -v

Conclusions

At the end of this exercise, your machine is now ready with the Node installed for
further development. We will examine web development tools next.

Basics of Node.js and NPM

Objectives and Outcomes

In this exercise you will learn the basics of Node and NPM. At the end of this
exercise, you will be able to:

 Set up package.json file in the project folder for configuring your Node and
NPM for this project

 Install a NPM module and make use of it within your project

Initializing package.json

 At the command prompt in your online-repo folder (Exercise 3), type

npm init

 Follow along the prompts and answer the questions as follows: accept the
default values for most of the entries, except set the entry point to index.html

 This should create a package.json file in your online-repo folder.

3
Installing an NPM Module

 Install an NPM module, lite-server, that allows you to run a Node.js based
development web server and serve up your project files. To do this, type the
following at the prompt:

npm install lite-server --save-dev

 You can check out more documentation on lite-server here.

 Next, open package.json in your editor and modify it as shown below. Note the
addition of two lines, line 7 and line 9.

 {
 "name": "git-test",
 "version": "1.0.0",
 "description": "This is the Git and Node basic learning project",
 "main": "index.html",
 "scripts": {
 "start": "npm run lite",
 "test": "echo \"Error: no test specified\" && exit 1",
 "lite": "lite-server"
 },
 "repository": {
 "type": "git",
 "url": "git+https://[email protected]/jogesh_k_muppala/git-
test.git"
 },
 "author": "",
 "license": "ISC",
 "homepage": "https://bitbucket.org/jogesh_k_muppala/git-test#readme",
 "devDependencies": {

4
 "lite-server": "^2.2.2"
 }
 }

 Next, start the development server by typing the following at the prompt:

npm start

 This should open your index.html page in your default browser.

 If you now open the index.html page in an editor and make changes and save,
the browser should immediately refresh to reflect the changes.

Setting up .gitignore

 Next, create a file in your project directory named .gitignore (Note: the name
starts with a period)Then, add the following to the .gitignore file

node_modules

 Then do a git commit and push the changes to the online repository. You will
note that the node_modules folder will not be added to the commit, and will not
be uploaded to the repository.

Conclusions

In this exercise you learnt to set up package.json, install a npm package and start a
development server.

You might also like