Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Backend Initialization Guide

This guide explains the complete process of initializing a backend project and editing the package.json file for beginners.

1. Create or open the backend folder

  1. Open your terminal or command prompt.
  2. Navigate to the backend folder:
    cd <your folder path>
  3. If the folder does not exist, create it first, then navigate into it.

2. Initialize npm in the folder

  1. Run the npm initialization command:
    npm init -y
  2. This creates a package.json file with default values.
  3. If you want to customize values, run:
    npm init
    and answer the prompts.

3. Understand the default package.json content

After initialization, package.json typically contains:

  • name: the project name
  • version: the project version
  • description: a short description
  • main: the entry file (usually index.js)
  • scripts: commands you can run with npm run
  • author: your name or organization
  • license: the project license

4. Edit package.json for a backend project

Open package.json in a code editor and update these sections:

  • name: use a lowercase, hyphenated name.
  • version: keep as 1.0.0 for a new project.
  • description: write a short description.
  • main: set the entry point, for example server.js or app.js.
  • scripts: add useful commands:
    "scripts": {
      "start": "node server.js",
      "dev": "nodemon server.js"
    }
  • dependencies: will list runtime packages like express, mongoose, etc.
  • devDependencies: will list development tools like nodemon.

Example package.json structure:

{
  "name": "backend",
  "version": "1.0.0",
  "description": "MERN backend project",
  "main": "server.js",
  "scripts": {
    "start": "node server.js",
    "dev": "nodemon server.js"
  },
  "author": "Your Name",
  "license": "MIT"
}

5. Install backend packages

  1. Install Express:
    npm install express
  2. Install development tools like nodemon:
    npm install --save-dev nodemon
  3. Install other packages as needed, e.g.:
    npm install mongoose dotenv

6. Use the scripts in package.json

  • Start the server:
    npm start
  • Start in development mode with auto-reload:
    npm run dev

7. Save your changes

  1. After editing package.json, save the file.
  2. Confirm the file is valid JSON by checking commas, braces, and quotes.
  3. Run npm install if you add new dependencies.

8. Summary

  • Initialize the backend folder with npm init -y.
  • Edit package.json to set the entry file and scripts.
  • Install needed packages with npm install.
  • Use npm start or npm run dev to run the backend.

About

Express.JS backend project for the online class of MERN Stack course with BCE 2022 Batch.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages