Copyright Derek O'Reilly, Dundalk Institute of Technology (DkIT), Dundalk, Co. Louth, Ireland.
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
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.
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):
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.
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.
Copyright Derek O' Reilly, Dundalk Institute of Technology (DkIT), Dundalk, Co. Louth, Ireland.