Simplified some things
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>MERN_STACK</title>
|
||||
<title>MERN Application</title>
|
||||
</head>
|
||||
<body>
|
||||
<noscript>You need to enable JavaScript to run this app.</noscript>
|
||||
|
||||
@@ -2,16 +2,15 @@ import Example from './../models/model.js';
|
||||
|
||||
const getExamples = (request, response) => {
|
||||
// what is .find() ??? ---> https://mongoosejs.com/docs/queries.html
|
||||
Example.find((error, allExamples) => {
|
||||
Example.find((error, data) => {
|
||||
if (error) {
|
||||
console.log(`❌ ${error}`);
|
||||
return response.status(404).json(error); // 404 not found + catched error -> send to client
|
||||
} else {
|
||||
console.log('✅ -FOUND- :', data);
|
||||
return response.status(200).json(data); // 200 ok + array of documents -> send to client
|
||||
}
|
||||
|
||||
// more about response status codes ---> https://restapitutorial.com/httpstatuscodes.html
|
||||
|
||||
console.log('✅ -FOUND- :', allExamples);
|
||||
return response.status(200).json(allExamples); // 200 ok + array of couments -> send to client
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
import express from 'express';
|
||||
import getExamples from './../controllers/controller.js'; // import request & response function
|
||||
|
||||
const router = express.Router(); // initialize router
|
||||
|
||||
/*
|
||||
1st param = extended path location
|
||||
2nd param = request & response function
|
||||
|
||||
current link: http://localhost:8080/examples
|
||||
*/
|
||||
router.get('/examples', getExamples);
|
||||
router.get('/examples', getExamples); // current path: http://localhost:8080/examples
|
||||
|
||||
export default router;
|
||||
|
||||
Reference in New Issue
Block a user