- 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.
推薦閱讀
- 極簡(jiǎn)算法史:從數(shù)學(xué)到機(jī)器的故事
- JSP網(wǎng)絡(luò)編程(學(xué)習(xí)筆記)
- Java異步編程實(shí)戰(zhàn)
- 大學(xué)計(jì)算機(jī)應(yīng)用基礎(chǔ)實(shí)踐教程
- Effective Python Penetration Testing
- Magento 1.8 Development Cookbook
- Swift細(xì)致入門與最佳實(shí)踐
- Mastering Android Development with Kotlin
- Python程序設(shè)計(jì)與算法基礎(chǔ)教程(第2版)(微課版)
- 微信小程序開發(fā)實(shí)戰(zhàn):設(shè)計(jì)·運(yùn)營(yíng)·變現(xiàn)(圖解案例版)
- 深入解析Java編譯器:源碼剖析與實(shí)例詳解
- 計(jì)算機(jī)應(yīng)用基礎(chǔ)(第二版)
- 深度學(xué)習(xí)程序設(shè)計(jì)實(shí)戰(zhàn)
- Flink核心技術(shù):源碼剖析與特性開發(fā)
- Visual C++ 2017網(wǎng)絡(luò)編程實(shí)戰(zhàn)