The path to require is relative to the module invoking require(). If
you want to access users.js from routes.js you have to invoke
require('../models/users').

Moreover, try not to use case sensitive paths in your require calls,
because Node could evaluate your modules different times if you use
two paths with different case-sensitivity to access the same module.
See [1] for more details.

[1]: https://github.com/joyent/node/issues/6829

2014-04-21 1:43 GMT+02:00 Alejandro Paciotti <[email protected]>:
> I am structuring my node.js application with express as follows:
>
> myApp
> - app
> ---- config
> ---- models
> -------- users. js
> ---- routes
> -------- routes. js
>
> - node_modules
> package.json
> server.js
>
>
> I create a variable User in the file server.js  and work fine.
>
> User = require (‘./App/models/users’)
>
>
>
> But if I write the same sentence in the file routes.js I get the following
> error message:
>
> Can not find module './App/models/users'
>
>
> How I can reference an object in a js file in a subfolder?
>
>
> Thanks in advance.
>
>
>
> [email protected]
>
> --
> --
> Job Board: http://jobs.nodejs.org/
> Posting guidelines:
> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> You received this message because you are subscribed to the Google
> Groups "nodejs" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en
>
> ---
> You received this message because you are subscribed to the Google Groups
> "nodejs" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.

-- 
-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to