Thank you. I may have caused a misunderstanding. I have about 20 .js files that I would like to combine into a single module. I would like to do one require and have access to the functions detailed in each of the 20 files. Thus a library.
On Friday, April 18, 2014 1:12:01 PM UTC-5, Francesco Mari wrote: > > You need to create separate projects for each of your modules, and > install each module via NPM. Please read the documentation about > modules [1] to understand how the modules are loaded. You may also > want to read one of the many tutorials about NPM. > > One higher level consideration. You describe your application as > composed of different modules, each of them performing a specific task > in your application. If those modules are highly coupled, or if it > doesn't make sense to publish each of them as standalone modules, you > should probably re-think the design of your application. > > [1]: http://nodejs.org/docs/latest/api/modules.html > > 2014-04-18 15:57 GMT+02:00 Kevin Burton > <[email protected]<javascript:>>: > > > This is probably a very basic question but I could not find a definitive > > answer right away so I am hoping someone on this group would be willing > to > > provide me with some insight. > > > > Right now I have an application that is split into various .js files. > Each > > file performs a specific function. For example I invoke 'node > > presentation.js' and that makes various database and WebAPI calls to get > > information about a 'presentation'. There are about 20 of these types of > > JavaScript files and I could write a script to invoke each one of them > like > > 'node xxx.js'. But what I would prefer to do is to have a single > 'app.js' > > file that would contain something like the following lines: > > > > var foo = require('foo'); > > foo.presentation(); > > foo.folder(); > > . . . . > > etc > > > > Then invoke this single file like 'node app.js'. In other words I would > like > > a library. I have put in presentation.js and similar files an 'exports' > like > > exports.presentation = function () { . . . .}; But my first hurdle is in > the > > lines above I get an error from 'require('foo')' that indicates 'Cannot > find > > module 'foo''. I know I can 'require('./presentation.js') and it will > find > > the JavaScript file starting with the current folder but I would like > more > > of a library. So to put the question succinctly I would like to know how > to > > structure my folders so the require would pull in a library of functions > > each defined by a separate .js file? Pointers? Ideas? > > > > Thank you. > > > > -- > > -- > > 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]<javascript:> > > To unsubscribe from this group, send email to > > [email protected] <javascript:> > > 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] <javascript:>. > > 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.
