Create a Node.js Project

Node.js can run from any folder on your computer. We shall set up a folder called "nodejs_projects" on the c: drive to hold all of our Node.js projects

Use Windows Explorer to set up a folder called "nodejs_projects" on the c: drive

c:\nodejs_projects

Within this folder, we shall set up a sub-folder for each project that we make.

For example, we shall create a sub-folder called "server_test" to hold a project.

c:\nodejs_projects\server_test

 

We must set up Node.js for each project sub-folder. To set up Node.js in the "c:\nodejs_projects\server_test" folder, we navigate to this folder in the cmd shell and then run the command below (Note that we must be in the correct folder when running the cmd):

npm init

This will install npm in the current folder, as shown below. Note that you can accept all of the default values during the installation.

The "npm init" command copies various folders and files that are needed for Node.js to run in a given project folder. Check your project folder structure to see the additional folders and files.

We can now use npm to install various packages into our Node.js "server_test" project. It is important to note that all packages that are installed are local to the project folder that they have been installed into.

For example, to install the "express" package into the current project, type the command below. Do not worry about any warning messages that are produced.

npm install express

The "npm install express" command copies various folders and files that are needed for Node.js to run express in a given project folder. Check your project folder structure to see the additional folders and files.

Create a sub-folder called "public" inside the "server_test" folder, as shown below.

c:\nodejs_projects\server_test\public

This folder will be used to hold the files that will be viewable on the user's browser.

The initialisation and installation set-up steps only need to be done once for each project. The set-up remains intact after the computer has been re-booted.

 
<div align="center"><a href="../../versionC/index.html" title="DKIT Lecture notes homepage for Derek O&#39; Reilly, Dundalk Institute of Technology (DKIT), Dundalk, County Louth, Ireland. Copyright Derek O&#39; Reilly, DKIT." target="_parent" style='font-size:0;color:white;background-color:white'>&nbsp;</a></div>