I don't know why you need a "single file" for your application.

Usually, your main app do:

// app.js
var entry = require('./entry.js');

If entry.js needs dependency, then

// entry.js
var dependency = require('./dependency.js');

If you need dependency from app.js too, then

// app.js
var dependency = require('./dependency.js');

dependency.js is loaded only one, the second require returns a "cache"
version.

I usually make a single file, not for Node.js, but for JavaScript modules
(developed for node) that now I want to run on browser.

What is your use case?

Angel "Java" Lopez
@ajlopez



On Mon, May 19, 2014 at 9:36 AM, Michael DeMond <[email protected]>wrote:

> WOW.... thank you so much everyone for your help, comments and feedback.
>  Now I know for a fact where to go whenever I have a question about
> Node.js. :)
>
> My problem had to do with how I was packaging my code for my Node.js
> application.  Essentially, I was creating a single "application.js" file,
> but the contents would be:
>
> <entry.js>
> <dependency.js>
>
> entry.js was referencing elements in dependency.js, but since
> dependency.js was being emitted *after* entry.js, I was getting a
> ReferenceError at runtime.  By putting my entry.js in a setTimeout (with
> 0ms), I was able to work around this problem.  setTimeout has always seemed
> like a hack to me, so I try to avoid it at all costs, but here it seems
> like a good use of it.
>
> Anyways, I was able to address my problem.  Thanks again all for your help!
> Michael
>
>
> On Sunday, May 18, 2014 11:52:34 PM UTC-7, Kevin Ingwersen wrote:
>
>> Hey.
>>
>> No, there is no such event in nodejs. But there are libraries that offer
>> such functionality, as far as I am aware. But, I would suggest something
>> like this.
>>
>> var myModule = require(…);
>> function initialize() {
>> // put some code here
>> }
>> (function(){
>> initialize();
>> // do stuff here.
>> })();
>>
>> I saw this sort of structure being used in the web as well as in nodejs.
>> From what I know about javascript itself: the function expression is
>> evualted, and then executed immediately. Since its after your init
>> function, it should be ran just then, when your code is set up.
>>
>> But dont take my word for the gold; I could be all wrong too. :) But its
>> a point to start at, I bet.
>>
>> Kind regards, Ingwie.
>>
>>
>> --
>> "Yo Dawg, I heard you like C++, so I  added C++ to your build system, so
>> you have to compile before you compile.“ -StackOverflow, Matt Joiner (
>> http://stackoverflow.com/a/5025525/2423150 )
>>
>> Am 18.05.2014 um 23:20 schrieb Michael DeMond <[email protected]>:
>>
>> Hello Community,
>>
>> Total Node newb here. :)  I just started a few weeks ago and have been
>> learning it.  I am curious if there is an equivalent to a window.onload
>> event handler in NodeJS.  Essentially, I am looking to execute a delegate
>> when all of the code in my NodeJS application has loaded.
>>
>> Thank you for any assistance you can lend,
>> Michael
>>
>> --
>> Job board: http://jobs.nodejs.org/
>> New group rules: https://gist.github.com/othiym23/9886289#file-
>> moderation-policy-md
>> Old group rules: 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 unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> To post to this group, send email to [email protected].
>>
>> To view this discussion on the web visit https://groups.google.com/d/
>> msgid/nodejs/d3f86cea-2079-4c89-9a46-bba931f2850a%40googlegroups.com<https://groups.google.com/d/msgid/nodejs/d3f86cea-2079-4c89-9a46-bba931f2850a%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>>
>>  --
> Job board: http://jobs.nodejs.org/
> New group rules:
> https://gist.github.com/othiym23/9886289#file-moderation-policy-md
> Old group rules:
> 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 unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/nodejs/eda70092-dd72-4827-ba2c-af87b8d8b6ab%40googlegroups.com<https://groups.google.com/d/msgid/nodejs/eda70092-dd72-4827-ba2c-af87b8d8b6ab%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
Job board: http://jobs.nodejs.org/
New group rules: 
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/CAMs%2BDqLd%3D%3D5iXim86S97dTsgTzy2cezEdasAoH33%3DDLmQaK1tg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to