Create a sample project with NodeJS and NPM

This is a broad overview and introduction to NodeJS. It will cover quite a few things that you can do with NodeJS without going too deeply into them. But it should give you a good idea of what you can do with NodeJS.

You must have NodeJS (and NPM) installed. You can install NodeJS by going to this page. NodeJS is the runtime program that can execute your JavaScript code (up until now, all of our JavaScript code has been executed by a browser). When you install NodeJS, NPM will also get installed.
NPM is a tool that you can use to install JavaScript packages (NPM = Node Package Manager).

Setting up the project

Create a folder named node-sample-project (but make sure NOT to put it inside a folder that is already a Git repository, becuase we'll make a Git repo for this folder later). The node-sample-project folder will be our project folder, and you'll see me make references to the 'project folder' in my instructions below.

Open a terminal and cd into the project folder that you just created.

Initialize a Node project by running this command (if you are using Windows 11 you may see an error when you run this command, you may need to set the execution policy in PowerShell):

npm init -y

This will create a file named package.json which is required for all npm projects. We'll talk more about this important file, but for the moment just know that it is a file that has information about your project.

Now, create a folder named samples inside the project folder (the node-sample-project folder). We'll put most of our sample programs in this folder.

Later we'll be creating some custom modules, so add a modules folder to the project folder.

Add a README.md file to the project folder.

Add a heading to the readme file that says Node Sample Project.

Add a .gitignore file to the project folder and put this in it:

node_modules

We'll be talking more about the node_modules folder later, but for now just note that you do NOT want Git to track the files in it. So, by creating a .gitignore file nad adding 'node_modules' to it, Git will ignore the folder completely

Initialize a git repository by running this command:

git init

Add and commit the files we've created by running these commands:

git add .
git commit -m "First commit"

Now, let's create a separate branch, so that we can easily return our project to the current state if we need to. Run this command:

git branch 1-setup-complete

Finally, make sure to publish/push both branches to GitHub (there are different ways to do this, we can go over them in class, just ask me).

In the next lesson, you'll learn about File IO in NodeJS