Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/soumyadip007/curd-application-using-node-express-mongo
In computer programming, create, read, update, and delete are the four basic functions of persistent storage. Alternate words are sometimes used when defining the four basic functions of CRUD, such as retrieve instead of read, modify instead of update, or destroy instead of delete.
https://github.com/soumyadip007/curd-application-using-node-express-mongo
async await db express modelviewcontroller mongo mongodb mongoose node promise
Last synced: 21 days ago
JSON representation
In computer programming, create, read, update, and delete are the four basic functions of persistent storage. Alternate words are sometimes used when defining the four basic functions of CRUD, such as retrieve instead of read, modify instead of update, or destroy instead of delete.
- Host: GitHub
- URL: https://github.com/soumyadip007/curd-application-using-node-express-mongo
- Owner: soumyadip007
- License: mit
- Created: 2020-11-18T16:30:38.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2021-06-14T07:24:47.000Z (over 3 years ago)
- Last Synced: 2024-11-09T23:37:14.386Z (3 months ago)
- Topics: async, await, db, express, modelviewcontroller, mongo, mongodb, mongoose, node, promise
- Language: JavaScript
- Homepage:
- Size: 50.8 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# CURD-Application-using-Node-Express-Mongo
In computer programming, create, read, update, and delete are the four basic functions of persistent storage. Alternate words are sometimes used when defining the four basic functions of CRUD, such as retrieve instead of read, modify instead of update, or destroy instead of delete.### Config File
```
const express = require('express')
const mongoose = require('mongoose')const app=express()
const url='mongodb://localhost:27017/mi'
mongoose.connect(url, {useNewUrlParser:true})
const con=mongoose.connectioncon.on('open', function(){
console.log('MongoDb Connected')
})
app.use(express.json())//Forwarding Endpoints
const allienRouter= require('./routes/aliensController')
app.use('/aliens', allienRouter)app.listen(9000, () =>{
console.log("Server Started")
})
```### Schema File
```
const express = require('express')
const mongoose = require('mongoose')const alienSchema= new mongoose.Schema({
name:{
type:String,
required: true
},
tech:{
type:String,
required: true
},
sub:{
type:String,
required: true,
default:false
}
})module.exports = mongoose.model('AlienMyAliean',alienSchema)
```
### Router File
```
const express = require('express')
const router=express.Router()
const AlienData=require('../models/alien')router.get('/', async(req,res)=>{
console.log('Get Request')
try{
const aliens= await AlienData.find()
res.json(aliens)
}catch(e){
res.send('Error'+e)
}})
router.post('/', async function (req, res) {
console.log('Post Request')
const alien = new AlienData({
name: req.body.name,
tech: req.body.tech,
sub: req.body.sub
})
console.log(alien)
try {const a1 = await alien.save()
res.json(a1)} catch (e) {
res.send('Error' + e)
}})
router.post('/', async (req, res) => {
console.log('Post Request')
const alien = new AlienData({
name: req.body.name,
tech: req.body.tech,
sub: req.body.sub
})
console.log(alien)
try {const a1 = await alien.save()
res.json(a1)} catch (e) {
res.send('Error' + e)
}})
router.get('/:id', async (req, res) => {
try {const alien = await AlienData.findById(req.params.id)
res.json(alien)} catch (e) {
res.send('Error' + e)
}})
module.exports = router
```