Skip to content

Pratham82/typescript-express-mongo-crud

Repository files navigation

TypeScript Express + MongoDB crud API

1. Usage

 

Installing packages:

npm i

 

Running Application

 

Build the project in javascript:

npm run build

Start the project:

npm run start

Development with typescript

npm run dev

Run application with docker

docker-compose up

 

2. API Documentation

 

Use Postman or Insomnia for testing the API:

We are working with User model here, following is the model schema

 {
   "name": "Tim Book",
   "age": 24,
   "designation": "Football Player",
  }

 

2.1 Routes:

 

GET

This route will give you all the users in database

localhost:3000/api/users/all

GET ONE

This route will give you the user with the provided ID

localhost:3000/api/users/find/:id

POST

Creating new user with the given Request body in JSON

localhost:3000/api/users/new

Eg. Request body

 {
   "name": "Tim Book",
   "age": 24,
   "designation": "Football Player",
 }

DELETE

This route will delete the user with the provided ID

localhost:3000/api/users/delete/:id

UPDATE

This route will update the user with the provided ID and given Request body in JSON

localhost:3000/api/users/update/:id

Notes

Fixing npm run build errors

sudo rm -rf node_modules/ package-lock.json

Build project again

npm run build

Change ownership of data folder

sudo chown -R $USER data

About

CRUD API with typescript, exprees and mongoose

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published