Full of CRUD

In the last month i’ve had to deal with a lot of CRUD. Seriously, it seems to be all I do know a days. If you are not aware, CRUD stands for Create, Read, Update, and Delete operations. These operations are used when manipulating data in a database, like mysql or mongodb. This is how the server communicates with the database and how the client communicates with the server.

These operation normally are called GET, POST, PUT, and DELETE, but I guess that doesn’t sound as good a crud. Here is an example of CRUD operation using mongoose.

let mySchema = mongoose.Schema({ name: String, age: String})
let myData = mongoose.model('myCreation', mySchema);
app.post('/CREATE', (req, res) => {
new myData(req.body).save((err) => {
if(err){ console.log(err)}
});
res.redirect('/');
});

Once we get a POST request to ‘/CREATE’ form the client, this lets us know we want to create data in the database.

app.get('/READ', (req, res) => {
myData.find(req.body, (err, all) => {
if (err) { console.log(err) }
res.send(all);
});
});

Same thing goes for a GET request to ‘/READ’. We know from this the client is requesting information from the database to read. These are just simple examples on how to create and read information in a database using CRUD operations.