- 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.
推薦閱讀
- MySQL數(shù)據(jù)庫管理實戰(zhàn)
- 在最好的年紀學Python:小學生趣味編程
- LabVIEW2018中文版 虛擬儀器程序設計自學手冊
- Getting Started with ResearchKit
- Bulma必知必會
- Cassandra Data Modeling and Analysis
- Nginx Essentials
- JSP開發(fā)案例教程
- R語言與網(wǎng)絡輿情處理
- ASP.NET程序開發(fā)范例寶典
- Python Essentials
- PHP 8從入門到精通(視頻教學版)
- Scrapy網(wǎng)絡爬蟲實戰(zhàn)
- Deep Learning for Natural Language Processing
- 現(xiàn)代C++語言核心特性解析