Generating the Express Project

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

  1. Open your terminal.
  2. Create a new directory for your project. For example:mkdir bookstore cd bookstore You can name the project whatever you want; here, we’ll use bookstore.

Step 2: Initializing the Project

  1. Run the following command to initialize a new Node.js project:npm init
  2. 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.

Once complete, you’ll see a package.json file created in your project directory.

Step 3: Installing Express

  1. Install Express by running:npm install express
  2. 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 to package.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!

Leave a Reply

Your email address will not be published. Required fields are marked *