Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

app.use(require('./controllers')) doesn't work #2

Open
JLGouwy opened this issue Jun 10, 2015 · 1 comment
Open

app.use(require('./controllers')) doesn't work #2

JLGouwy opened this issue Jun 10, 2015 · 1 comment

Comments

@JLGouwy
Copy link

JLGouwy commented Jun 10, 2015

Hi,

i decided to learn node/express JS. And i want to begin with a good start, a good structure directly. And yours seems really fine.

I'm trying to adapt mine to yours, but i've few questions.

When I put this line "app.use(require('./controllers'))", the console said me "controller module doesn't exist" !
How does it work this middleware ?
if i understand, when you write this line, you "include" all controller file, right ?

Until now, i learned that all modules have to localize to node_modules folder. So, i suppose that the middleware tried to find controller.js in this folder.

Can you enlighten me ?

Thanks to share your knowledge,
Appreciate.

JL, from Belgium.

@ulisesqg
Copy link

ulisesqg commented Feb 1, 2016

Hi, im new in Javascript world too and im learning Express. that line gets confused to me too. but reading about 'require()' i realize when you require a folder, it search a file with the same name of the folder plus .js extension. if not find that, try to require a index.js (or other files). So, in the 'controllers' folder there is a index.js which 'use' the users.js and comments.js and exports in router.

Cheers.

https://nodejs.org/api/modules.html#modules_folders_as_modules

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants