I don't think it's a hack. Rather elegant, really:
mkdir node_modules
mv path/to/component.js node_modules/component.js
node -pe "require('component') // voila"
You could also make it a full-fledged package (jus a matter of adding
one extra file package.json, which npm can do for you, though a README
and LICENSE are strongly encouraged as well), and then list it as a
dependency. That's the more "traditional" way that people handle
dependencies like this. npm ignores anything in node_modules that
isn't a package, so it should be fine just leaving it there,
otherwise.
On Fri, Feb 8, 2013 at 5:24 PM, Geerten van Meel <[email protected]> wrote:
> Hi,
>
> I am working on an app and would like to access a component of my app simply
> using require('component') instead of require('./component') or worse
> require('./path/to/component.js'). I know that there are ways to achieve
> this by doing some hack regarding the node_modules folder, but I would like
> to ask whether there is a simple, elegant way to achieve this result (and
> not interfere with npm when deploying)?
>
> To summarize:
>
> - I would like to include an app component using require('component')
> instead of require('./path/to/component.js').
>
> - The components location should ideally be somewhere out of node_modules
> in order to not mess with npm.
>
> - NODE_PATH, thus process arguments should not be provided via the command
> line.
>
> Thank you for your time and suggestions!
>
> Geerten
>
> --
> --
> 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/groups/opt_out.
>
>
--
--
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/groups/opt_out.