https://github.com/piyush-linux/crud
CRUD Node
https://github.com/piyush-linux/crud
Last synced: 6 months ago
JSON representation
CRUD Node
- Host: GitHub
- URL: https://github.com/piyush-linux/crud
- Owner: Piyush-linux
- Created: 2021-07-06T04:29:25.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2021-07-10T06:47:32.000Z (almost 5 years ago)
- Last Synced: 2025-04-08T14:15:10.637Z (over 1 year ago)
- Language: HTML
- Size: 343 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 
# Setup
```sh
> mkdir PJ
> cd PJ
> touch server.js
> npm init -y
> npm i express nodemon body-parser mongoose pug dotenv morgan axios
> packag.jso >> {"main": "server.js" , "npm start":"node server.js"}
```
# Folder Structure
```sh
# git ignore
node_modules
.env
# git push
package.json
/server.js
/public/ { css , js , img }
/views/ {index.pug , partial(header.pug , footer.pug) }
/server
/controller
/model
/database
/routes
/services
```
### 1. Creating Server
- init exp with env.PORT
### 2. Middleware security, client, request, static
### 3. HTML Template
- header
- add user > form(id, name, email, gender)
- All user : table
= usr + edit + del
### 4. load routes
1. routes/router.js
```sh
> GET /
> GET /adduser
> GET /updateuser
```
2. /services/render.js > res.render( function )
3. /server.js > use router
### 5. db connect
- server/connect.js > connect(db) with mongoose
- .env security key : usr:pasw?dbname
### 6 API
```sh
# render
> GET /
> GET /add_user
> GET /update_user
# API
> GET /api/usr
> POST /api/usr
> PUT /api/usr/:id
> DEL /api/usr/:id
```
1. crt Rules
- /modl/model.js : exp>rules
2. crt CRUD opr
- /controller/controller.js : req rules > export.CRUD function
- /router/router.js > router.request(path,controller.CRUD)
1. create
- get req.data
- insert data
2. read
- fetch all data
3. update
- get req.id
- find in db
- then update
4. delete
- get req.id
- find in db
- then delete
3. Render
- sevices/render.js exp.root > render()
- render: fetch through api with axios
- all user > PUG iterate with data | update user | create user
1. GET /
- get data from api
- render in loop in pug with usr.id
2. POST /add_user
- insert data to api
- redirect to /
3. PUT /api/:id
- get qry id
- find in api
- upt to db
- redirect /
4. DELETE /api/:id
- get qry id
- find in db
- del to db
- redirect /
5. Deployment
- ! Replace local_host with server_host for API call
- https://localhost:3000 with https://website.com"
- git push with only bash for extra prevention