https://github.com/ayushbobale/expressbackend
This is an interview assesment.
https://github.com/ayushbobale/expressbackend
Last synced: 3 months ago
JSON representation
This is an interview assesment.
- Host: GitHub
- URL: https://github.com/ayushbobale/expressbackend
- Owner: AyushBobale
- Created: 2022-10-28T15:55:56.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-10-28T17:50:22.000Z (over 2 years ago)
- Last Synced: 2025-01-13T03:45:17.039Z (4 months ago)
- Language: JavaScript
- Size: 692 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# CRUD app /API using Node.js
## Note
---A better folder structure could be used since the project was small I kept all the files in the root folder
A better approach would be```
server
│ index.js
│
└───routes
│ │ route1.js
│ │ route2.js
│
└───models
│ │ Model1.js
│ │ Model2.js
│
└───middleware
│ │ middleware1.js
│ │ middleware2.js
│
└───controller
│ │ controller1.js
│ │ controller2.js
│
└───config
│ config.js
│
```## How to run
---``` bash
npm install
cd server
npm run develop # To start a development server
```
```bash
npm install
cd server
npm start # To start a Production server
```---
## Libraries used
* express
* To create a server
* express-async-handler
* To have better error handling and readable code
* mongoose
* To connect to mongodb/atlas
* dotenv
* storing sensitive env vars
* cors
* allowing for cross origin requests
* nodemon [dev dependency]
* dev dependency---
## Flow
1. Create an express app
2. Add cors middle ware
3. Connect to db
4. Use the router middleware
5. In router middleware define all the routes for different methods
6. Create a controller file
7. Inside the controller file define methods to be passed as arguments to the routes defined in router file
8. Create the DataModel with apropriate schema
9. Use the Model in the controller file to interface with the database
10. Create an error handler middle ware and write appropriate logic in it
11. Use the error handler middleware at last in the index file---
## Outputs
* Get Request

* Post Request

* Get after Post Request

* Update Request [old image new update uses params]

* Get after Update Request

* Delete Request [old image new update uses params]

* Get after Delete Request
