- What is the best/most common file structure for backend NodeJS projects?
- What is the MVC architecture? Why we will be using it?
- Explore defining a schema in Mongoose, you can refer to this for more information (no answer in the comments required).
- What are the CRUD operations? add an example code of each CRUD operations in Mongoose.
-
-
Save halitbatur/4b641bd64249880151a83082f35cc5eb to your computer and use it in GitHub Desktop.
Teammates: Nilay, Rasha, Mohammad Ibrahim
What is the best/most common file structure for backend NodeJS projects?
there some rules to best orgnizing our nodejs project, we could put some here:
Rule 1 – Organize your Files Around Features, Not Roles
Rule 2 – Don’t Put Logic in index.js Files
Rule 3 – Place Your Test Files Next to The Implementation
Rule 4 – Use a config Directory
Rule 5 – Put Your Long npm Scripts in a scripts Directory
What is the MVC architecture? Why we will be using it?
Three Levels Of MVC Model :
-
Model –
This level is considered the lowest level when compared with the View and Controller. It primarily represents the data to the user and defines the storage of all the application’s data objects. -
Views –
This level is majorly associated with the User Interface(UI) and it is used to provide the visual representation of the MVC model. In simpler terms, this level deals with displaying the actual output to the user. It also handles the communication between the user (inputs, requests, etc.) and the controller. -
Controller –
This level takes care of the request handler. It is often considered as the brain of the MVC system- a link, so to speak, between the user and the system. The controller completes the cycle of taking the user output, converting it into desired messages, and passing them on to the views(UI).
and we will use it to orgnize our nodejs structure
Explore defining a schema in Mongoose, you can refer to this for more information (no answer in the comments required).
Everything in Mongoose starts with a Schema. Each schema maps to a MongoDB collection and defines the shape of the documents within that collection.
What are the CRUD operations? add an example code of each CRUD operations in Mongoose.
there are operations about Creating, Reading, Updating, Deleting documents in mongodb
Create ex.
router.get('/save', function(req, res) {
var newStudent = new StudentModel({StudentId:101,
Name:"Sam", Roll:1, Birthday:2001-09-08});
newStudent.save(function(err, data) {
if(err) {
console.log(error);
}
else {
res.send("Data inserted");
}
});
});
Read ex.
r```
outer.get('/findall', function(req, res) {
StudentModel.find(function(err, data) {
if(err){
console.log(err);
}
else{
res.send(data);
}
});
});
Update ex.
`router.post('/update', function(req, res) {
StudentModel.findByIdAndUpdate(req.body.id,
{Name:req.body.Name}, function(err, data) {
if(err){
console.log(err);
}
else{
res.send(data);
console.log("Data updated!");
}
});
});
`
Delete ex.
``router.get('/delete', function(req, res) {
StudentModel.remove({StudentId:188},
function(err, data) {
if(err){
console.log(err);
}
else{
res.send(data);
}
});
});
Ezgi Okur, Hafiz Mhammadah, Adnan Khaldar
What is the best/most common file structure for backend NodeJS projects?
What is the MVC architecture? Why will we be using it?
What are the CRUD operations? add an example code of each CRUD operations in Mongoose.