- 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.
推薦閱讀
- 零基礎(chǔ)學(xué)Visual C++第3版
- Visual Basic 6.0程序設(shè)計計算機組裝與維修
- Offer來了:Java面試核心知識點精講(原理篇)
- 零基礎(chǔ)入門學(xué)習(xí)Python(第2版)
- OpenResty完全開發(fā)指南:構(gòu)建百萬級別并發(fā)的Web應(yīng)用
- Learning jQuery(Fourth Edition)
- Python深度學(xué)習(xí)原理、算法與案例
- Practical GIS
- Python Programming for Arduino
- Python第三方庫開發(fā)應(yīng)用實戰(zhàn)
- MATLAB 2020 GUI程序設(shè)計從入門到精通
- Java面向?qū)ο蟪绦蛟O(shè)計教程
- Java編程指南:語法基礎(chǔ)、面向?qū)ο蟆⒑瘮?shù)式編程與項目實戰(zhàn)
- Mastering Python
- C++游戲設(shè)計案例教程