You do not have permission to delete messages in this group
Copy link
Report message
Sign in to report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to nod...@googlegroups.com
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.
Francesco Mari
unread,
Apr 18, 2014, 2:12:01 PM4/18/14
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Sign in to report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to nod...@googlegroups.com
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.
You do not have permission to delete messages in this group
Copy link
Report message
Sign in to report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to nod...@googlegroups.com
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.
Aria Stewart
unread,
Apr 18, 2014, 2:51:03 PM4/18/14
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Sign in to report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
> 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.