Welcome back, everyone.
Let’s start generating our project. This course assumes that you already have Node.js installed.
Step 1: Setting Up the Project Directory
- Open your terminal.
- Create a new directory for your project. For example:
mkdir bookstore cd
You can name the project whatever you want; here, we’ll usebookstore
bookstore
.
Step 2: Initializing the Project
- Run the following command to initialize a new Node.js project:
npm init
- Follow the prompts to set up your
package.json
file. You can use default values by pressing Enter for each prompt. Here are the typical prompts:- Package Name:
bookstore
- Version:
1.0.0
- Description: Add a short description or leave it blank.
- Entry Point:
app.js
(This will be the file where we write our server code.) - Keywords: Optional.
- Author: Enter your name or leave it blank.
- License: Use the default
MIT
license or choose another.
- Package Name:
Once complete, you’ll see a package.json
file created in your project directory.
Step 3: Installing Express
- Install Express by running:
npm install express
- Verify that Express has been added to your
package.json
under dependencies. For example:"dependencies": { "express": "^4.16.3" }
Note: In older versions of Node.js, you needed to use the
--save
flag to add dependencies topackage.json
. Modern versions of npm handle this automatically.
Step 4: Creating the Entry File
Now that the setup is complete, we’re ready to start writing our first file, app.js
. This will be covered in the next lesson.
Please check below screenshot for your references:
What’s Next?
In the next lesson, we’ll write the server code using Express and set up routes for our API. Stay tuned!