Skip to content

MohSensei/nodejs-express-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Node.js Express API

API built with Node.js, Express, and MongoDB to manage investors.

Installation

  1. Clone the repository:

    git clone <repository-url>
    cd <repository-directory>
  2. Install dependencies:

    npm install
  3. Set up environment variables: Create a .env file in the root directory with the following content:

    DATABASE_URL=mongodb://localhost:27017/yourDatabaseName
  4. Start the server:

    node server.js

    The server will start on port 3000.

Usage

Use tools like Postman or REST Client to interact with the API.

API Endpoints

Get All Investors

  • URL: /investors
  • Method: GET
  • Response:
    [
        {
            "_id": "unique_id",
            "name": "Investor Name",
            "investingToCompany": "Company Name",
            "investingDate": "2023-01-01T00:00:00.000Z"
        },
        ...
    ]

Get One Investor

  • URL: /investors/:id
  • Method: GET
  • Response:
    {
      "_id": "unique_id",
      "name": "Investor Name",
      "investingToCompany": "Company Name",
      "investingDate": "2023-01-01T00:00:00.000Z"
    }

Create One Investor

  • URL: /investors
  • Method: POST
  • Request Body:
    {
      "name": "Investor Name",
      "investingToCompany": "Company Name"
    }
  • Response:
    {
      "_id": "unique_id",
      "name": "Investor Name",
      "investingToCompany": "Company Name",
      "investingDate": "2023-01-01T00:00:00.000Z"
    }

Update One Investor

  • URL: /investors/:id
  • Method: PATCH
  • Request Body:
    {
      "name": "Updated Name",
      "investingToCompany": "Updated Company"
    }
  • Response:
    {
      "_id": "unique_id",
      "name": "Updated Name",
      "investingToCompany": "Updated Company",
      "investingDate": "2023-01-01T00:00:00.000Z"
    }

Delete One Investor

  • URL: /investors/:id
  • Method: DELETE
  • Response:
    {
      "message": "Deleted Investor"
    }

Environment Variables

Create a .env file in the root directory with the following content:

DATABASE_URL=mongodb://localhost:27017/yourDatabaseName

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published