- Node.js 6.x Blueprints
- Fernando Monteiro
- 164字
- 2021-07-14 10:35:04
Creating a controllers folder
- Create a folder called
controllers
inside the root project folder. - Create an
index.js
inside thecontrollers
folder and place the following code:// Index controller exports.show = function(req, res) { // Show index content res.render('index', { title: 'Express' }); };
- Edit the
app.js
file and replace the originalindex
routeapp.use('/', routes);
with the following code:app.get('/', index.show);
- Add the controller path to the
app.js
file right aftervar swig = require('swig');
declaration, replace the original code with the following code:// Inject index controller var index = require('./controllers/index');
- Now it's time to check if all goes as expected: we'll run the application and check the result. Type in your terminal/shell the following command:
npm start
Check the following URL: http://localhost:3000
, and you'll see the welcome message of express framework.
Removing the default routes folder
Let's remove the default routes
folder:
- Remove the
routes
folder and its contents. - Remove the
user route
from theapp.js
, after the index controller line.
推薦閱讀
- Dynamics 365 for Finance and Operations Development Cookbook(Fourth Edition)
- TypeScript Essentials
- FuelPHP Application Development Blueprints
- 編程卓越之道(卷3):軟件工程化
- 實用防銹油配方與制備200例
- C語言程序設計實訓教程
- GitLab Repository Management
- 零基礎學MQL:基于EA的自動化交易編程
- Learning AndEngine
- 名師講壇:Spring實戰開發(Redis+SpringDataJPA+SpringMVC+SpringSecurity)
- Learning ArcGIS for Desktop
- 蘋果的產品設計之道:創建優秀產品、服務和用戶體驗的七個原則
- 動手學數據結構與算法
- 一本書講透Java線程:原理與實踐
- Mastering Android Studio 3