Express应用程序中的helpers文件夹有何意义? [英] What's the significance of helpers folder in an Express app?

查看:53
本文介绍了Express应用程序中的helpers文件夹有何意义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试得出一种最适合我们需求的混合文件夹结构.

I am trying to derive a best hybrid folder structure, which suits our requirement.

但是在浏览了许多文章和信息之后.我有一个定义为 helpers 的文件夹,并且文件带有扩展名 .js 的文件.

But after going through many articles and information. I got a folder defined with name helpers and has files with .js extensions.

|-- app
|   |-- controllers
|   |   `-- userController.js
|   |-- models
|   |   `-- userSchemaModel.js
|   |-- routes
|   |   `-- index.js
|   `-- views
|       `-- userView.jade
|-- config
|   `-- AppConfig.js
|-- lib
|   `-- customLib.js
|-- vendor (or public)
|    |-- javascripts
|    |   |-- jquery.js 
|    `-- stylesheets
|        `-- StyleSheet.css
|-- app.js (startup)
`-- helpers
    `-- userHelper.js

谁能告诉我 helper文件夹 的重要性?

Could anyone tell me the significance of helper folder?

提前谢谢

推荐答案

我在这里猜测是因为您没有提及所使用的框架或已阅读的文章...

I'm guessing here because you haven't mentioned anything about what framework you're using or what articles you've read...

在Express框架中,帮助程序引用添加到模板上下文中的自定义变量和函数.在Express 3中,我认为它们被称为app.locals

In the Express framework, helpers refer to custom variables and functions that are added to your template context. In Express 3 I think they're referred to as app.locals

您可以在演示文稿代码中使用它们来处理可能经常使用但又不想使模板混乱的事物.日期格式,或从您的数据实体生成URL

You use them in your presentation code for things that might be used frequently but you might not want cluttering your templates... e.g. date formatting, or generating URLs from your data entities

这篇关于Express应用程序中的helpers文件夹有何意义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆