![](/img/trans.png)
[英]How do i take the value variable from a normal js file in the javascript folder to the routes/index.js file in nodejs and express?
[英]How do I split up index.js file in a node/mean/express application?
我的node / mongo / express應用程序有一個非常長的index.js路由文件。 這是結構。
app.js
/models
Schedule.js
Task.js
etc...
/routes
index.js
/public
/javascript
etc...
我想要這樣的東西
app.js
/models
Schedule.js
Task.js
etc...
/routes
index.js
schedule.js
tasks.js
etc...
/public
/javascript
etc...
如何分割index.js文件?
例如,我試圖在我的app.js文件中做類似的事情
var routes = require('./routes/index');
var tasks = require('./routes/tasks');
// later in the file
app.use('/', routes);
app.use('/tasks', tasks);
但是,它找不到我只有index.js之前的任務路徑。 這可能是因為我從route / index.js中提取了所有以“ / task”開頭的路由,並將它們放置在route / task.js中,但是為什么在這個新文件中表達出無法識別這些路由?
任何建議都將是有幫助的,我和我的朋友對整個meanjs的工作方式還很陌生,並且基本上將各種教程中的內容拼湊在一起。 現在我們迫切需要重構,因為route / index.js的使用時間太長了。 我盡力做到直觀上有意義的事情,在那里有人可以提供有關如何分解我們的路線文件的建議嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.