Amol M Kulkarni Amol M Kulkarni - 1 year ago 81
Node.js Question

What's the significance of helpers folder in an Express app?

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

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

Could anyone tell me the significance of helper folder?

Advance Thanks

Answer Source

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

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

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download