Open 3bdoYasser opened 11 months ago
CREATE package.json
{
"name": "simple-test",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.17.1"
}
}
CREATE app.js
const express = require('express');
const app = express();
const port = 3000;
app.get('/', (req, res) => {
res.send('Hello World!')
});
app.listen(port, () => {
console.log(`App listening at http://localhost:${port}`)
});
CREATE controllers/homeController.js
exports.index = function(req, res) {
res.send('Hello World!');
};
UPDATE app.js
const express = require('express');
const app = express();
const port = 3000;
const homeController = require('./controllers/homeController');
app.get('/', homeController.index);
app.listen(port, () => {
console.log(`App listening at http://localhost:${port}`)
});
CREATE models/homeModel.js
// This file is intentionally left blank as a placeholder for future model definitions.
CREATE views/homeView.js
// This file is intentionally left blank as a placeholder for future view definitions.
This structure follows the MVC (Model-View-Controller) architecture, where:
create nodejs project with MVC architecture.