[nodejs] Re: Server is accepting requests but is not responding. There is something hanging up the response.

2015-08-09 Thread zladuric
Well, in that case, I would say it looks like a memory leak or something. 
You say the socket should close in two minutes - are you leaving some 
closures there too? Maybe those get piled up and then afterwards they only 
accept new requests when old ones expire.

Did you count how many requests get piled up before this block?

Also, you seem to also be using third-party services - outgoing calls? Your 
global max of http connections is set?

Zlatko


On Sunday, August 9, 2015 at 3:21:23 AM UTC+2, Moacir Braga wrote:
>
> Hello Rob. I'm not using webpack nor sass.
>
> Zladuric, I'm logging the connections and I found one service that usually 
> is involved with the problem, however when I restart the application, I 
> create a request with the same logged data, but the problem does not 
> reproduce. Strange, right? Not be able to reproduce an error is really bad.
>
> I analysed the function, but all outputs are handled with HTTP 200 or 302, 
> i.e., I'm always closing the connections, but even if I don't, the socket 
> should do that in two minutes.
>
> Sometimes I think about if this problem happens only on Windows... but 
> unfortunately I must use Windows because this application is just a 
> middleware for my main solution.
>
> On Friday, August 7, 2015 at 12:51:17 PM UTC-3, Moacir Braga wrote:
>>
>> It’s been a few weeks since I started trying to solve this problem, but I 
>> still haven’t figured out a possible solution. The issue is that my server 
>> accepts requests and responds to them normally in the beginning. However, 
>> after an unknown event happens (I’m still trying to discover which event it 
>> is), the server continues accepting requests, but it stops responding to 
>> them.
>>
>>  
>>
>> I’ve already checked the Process Monitor (the server is running on 
>> Windows Server 2012 R2) and I could notice that when this problem happens, 
>> new requests generate a TCP Accept, a TCP Receive, but not a TCP Send nor a 
>> Disconnect.
>>
>>  
>>
>> I tried to execute the server in debug mode, but then again, when this 
>> problem happens the debugger does not work and it hangs up as well.
>>
>>  
>>
>> The server doesn’t explode and no errors occur. Thus, domains won’t help 
>> me in this case. I’ve tried to handle uncaughtException, but it also didn’t 
>> work.
>>
>>  
>>
>> The server keeps running without using excessive processor or memory 
>> resources. Its behavior is still similar to the one during the first 
>> execution, except for the fact that it’s not responding as it was before.
>>
>>  
>>
>> When I sent a SIGNAL via console, the server simply started working 
>> normally again without restarting or anything. It just got back to normal.
>>
>>  
>>
>> I tried to execute a lot of requests using ApacheBench and NeoLoad, but I 
>> just can’t reproduce this problem. It simply happens randomly.
>>
>>  
>>
>> The socket has a timeout of two minutes. However, the server keeps 
>> hanging up the requests for hours.
>>
>>  
>>
>> When I sent the SIGNAL mentioned before, all requests that were hanging 
>> were executed, as if they were in a queue waiting for the last request to 
>> be finished.
>>
>>  
>>
>> I don’t know what else could I do to find out what is causing this 
>> problem.
>>
>>
>> I'm using Node.js + Express + body-parser + cookie-parser + Windows 
>> Server 2012 R2 x64 with GUI + Amazon EC2 micro instance.
>>
>>
>> *If somebody has any idea of what is causing the server to hang up 
>> forever, please tell me.*
>>
>>
>> Best Regards,
>>
>> *Moacir Braga*
>>
>

-- 
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 nodejs+unsubscr...@googlegroups.com.
To post to this group, send email to nodejs@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/75a9f95f-f069-4449-b8d8-4bf2a8d20a01%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Re: Server is accepting requests but is not responding. There is something hanging up the response.

2015-08-08 Thread zladuric
A simple idea, but it might help:

Try to add logging middleware to your requests, which would also append 
something you can recognize. Something 
like https://github.com/villadora/express-bunyan-logger.

Then you might be able to compare which requests came in but are not 
finishing, and so piling up resources.

Another thing that comes to mind would be ulimit - but I don't know how to 
check that and even if it's a problem on Windows.


On Friday, August 7, 2015 at 5:51:17 PM UTC+2, Moacir Braga wrote:
>
> It’s been a few weeks since I started trying to solve this problem, but I 
> still haven’t figured out a possible solution. The issue is that my server 
> accepts requests and responds to them normally in the beginning. However, 
> after an unknown event happens (I’m still trying to discover which event it 
> is), the server continues accepting requests, but it stops responding to 
> them.
>
>  
>
> I’ve already checked the Process Monitor (the server is running on Windows 
> Server 2012 R2) and I could notice that when this problem happens, new 
> requests generate a TCP Accept, a TCP Receive, but not a TCP Send nor a 
> Disconnect.
>
>  
>
> I tried to execute the server in debug mode, but then again, when this 
> problem happens the debugger does not work and it hangs up as well.
>
>  
>
> The server doesn’t explode and no errors occur. Thus, domains won’t help 
> me in this case. I’ve tried to handle uncaughtException, but it also didn’t 
> work.
>
>  
>
> The server keeps running without using excessive processor or memory 
> resources. Its behavior is still similar to the one during the first 
> execution, except for the fact that it’s not responding as it was before.
>
>  
>
> When I sent a SIGNAL via console, the server simply started working 
> normally again without restarting or anything. It just got back to normal.
>
>  
>
> I tried to execute a lot of requests using ApacheBench and NeoLoad, but I 
> just can’t reproduce this problem. It simply happens randomly.
>
>  
>
> The socket has a timeout of two minutes. However, the server keeps hanging 
> up the requests for hours.
>
>  
>
> When I sent the SIGNAL mentioned before, all requests that were hanging 
> were executed, as if they were in a queue waiting for the last request to 
> be finished.
>
>  
>
> I don’t know what else could I do to find out what is causing this problem.
>
>
> I'm using Node.js + Express + body-parser + cookie-parser + Windows 
> Server 2012 R2 x64 with GUI + Amazon EC2 micro instance.
>
>
> *If somebody has any idea of what is causing the server to hang up 
> forever, please tell me.*
>
>
> Best Regards,
>
> *Moacir Braga*
>

-- 
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 nodejs+unsubscr...@googlegroups.com.
To post to this group, send email to nodejs@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/feebabcc-85d4-4744-9e74-06267e809f8c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Re: Data cache and lifetime

2015-07-15 Thread zladuric
If you want cache to survive reboots, you need to store all of the state 
externally, including any timeout/expiry conditions. One way to do it is to 
store the timeout (UTC) times together with the cache entry metadata. So an 
entry in your (simplified) cache collection would look like:

```
{
  "data": payload,
  "metadata": {
"type": "something",
"timeout": "2015-07-15T07:11:23.079Z"
  }

You'd need a load and store procedures too for the cache server which would 
recover all this and serialize/deserialize data, I guess.

On Tuesday, July 14, 2015 at 2:18:44 PM UTC+2, Ingwie Phoenix wrote:
>
> hey. 
>
> I want to implement a cache server that starts empty but can restore 
> itself after an exit from a JSON database. The principe of doing that seems 
> simple, but there is just one problem: the time-to-live parameter. 
>
> How can I best introduce a time-to-live, aka. time till the entry gets 
> purged automaticaly, in the best node-ish way? I know that just using a 
> setTimeout() would be a bad idea since the server might exit in the 
> meantime and the key and its value will just be carried over and not be 
> urged at the next run. 
>
> Any idea how I could implement this best? 
>
> Kind regards, Ingwie.

-- 
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 nodejs+unsubscr...@googlegroups.com.
To post to this group, send email to nodejs@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/f521dd50-9013-4922-bb5c-8829f516986c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Re: Newbie Question

2015-06-20 Thread zladuric
We set the port to whatever we want, but it's a common security and usage 
practice to not use "low ports" (lower then 1024) for app servers. In fact, 
in most operating systems, if you run the app server as a non-system user, 
you _cannot_ bind to such port.

The usual practice for Node.js (or, say, Tomcat, or Websphere or RoR or any 
other app servers) to be bound to some high port (above 1024) and then let 
nginx, apache, IIS or something else serve the port 80, and proxy over 
requests to the app server.

That way on one host you can even run multiple app servers with one web 
server.

Nothing would stop you to run as, say, root on Linux or a Mac, and bind the 
Node.js app to port 80, but then  your app has root privileges, and if your 
code (or some of the modules you use) is buggy or has security problems, 
your app would be a risk to the whole system.

Zlatko

On Saturday, June 20, 2015 at 3:43:51 AM UTC+2, Ray Jender wrote:
>
>
> So, for all of the example and demo code I have seen, they always include 
> doing "node file.js" and then it echos back "Listening at: 
> http://localhost:8080";  or similar.
> Which implies I have to browse to port 8080 to use the app.
>
> My question is how does this work in production?   I have never had to 
> browse to a website using a port number?   I'm confused?
> How can I simply browse to a URL and not include a port number?
>
> Thanks,
>
> Ray
>
>
>

-- 
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 nodejs+unsubscr...@googlegroups.com.
To post to this group, send email to nodejs@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/b84f439d-90ab-4115-b169-6538d941cd2d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Re: Large process getting slower and slower

2015-06-04 Thread zladuric
Well, for one, IIRC setImmediate will not put this step on the next loop - 
it will just append the function to the end of the current loop - thus 
never giving Node.js a chance to go off.

Another thing - did you try to use a debugger or something? Even a simple 
strace/dtrace would tell you what the node process is doing. Also, did the 
first program exit? Maybe it didn't and you're leaking more and more 
memory, thus swapping more and more?

On Thursday, June 4, 2015 at 5:06:38 AM UTC+2, Blake McBride wrote:
>
> Greetings,
>
> I have a large, very recursive process that (at best) takes 6 minutes to 
> run.  This process does a lot of IO, and a lot of directory recursion.  In 
> order to play nicely in a single threading event oriented system, I:
>
> 1.  use non-blocking function whenever available
>
> 2.  rather than perform recursion directly, I call the next step with 
> nextTick or setImmediate and exit
>
> This has worked well in my smaller databases, and the first time through 
> the large one (6 minutes).  But when trying to run the large one a second 
> time, it gets slower and slower until it kind of never ends.  I don't know 
> what is causing the slowdown.
>
> One thing I thought of is that perhaps I am filling the event queue in 
> such a way so that the IO never gets a chance and it has to go through 
> many, many events before any real IO can occur.  Don't know.
>
> Sure appreciate any ideas.
>
> Thanks.
>
> Blake McBride
>
>

-- 
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 nodejs+unsubscr...@googlegroups.com.
To post to this group, send email to nodejs@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/6c78c840-bcd9-4a1e-9139-58d05602b6d1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Struggling with port 80

2015-05-31 Thread zladuric
Port 80 is likely in use by apache or nginx. If it's one of them, you should 
either bring them down and let node take port 80, or, as is usual, forward 
requests that you want to node running on a high port, something above 1024.

-- 
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 nodejs+unsubscr...@googlegroups.com.
To post to this group, send email to nodejs@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/d0147366-8a50-4220-af39-cb6a0d320dc9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [nodejs] should I install io.js or node.js?

2015-05-22 Thread zladuric
One thing to keep in mind is to have the same platform to develop on and to 
deploy on (ie. server and your local workstation). Iojs and node.js have 
some (few) modules that do not work well accross the platforms, so you'd 
have to match those. Example, with some versions of mongoose I've had 
issues - stuff precompiled for Node would not work on Io or the other way 
around. Also, gulp has had some issues.

Another thing is stability. I would say iojs is stable, but they themselves 
are saying it's not production ready. I know that's just CYA talk, but I've 
listened to that advice and I use Node on production.



On Wednesday, May 20, 2015 at 2:56:15 PM UTC+2, Carlos Carcamo wrote:
>
> Hello all.
> Since the node.js foundation is a reality, I wonder what should I install 
> on my new server? the last version of io.js or the last version of node.js?
> What are your recommendation?
>
> Thanks in advance.
> -- 
> "El desarrollo no es material es un estado de conciencia mental"
>  

-- 
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 nodejs+unsubscr...@googlegroups.com.
To post to this group, send email to nodejs@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/079205d5-3894-4a88-bc2d-bb3c35c2a3bd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Event Queue Mechanism

2015-05-18 Thread zladuric
Yes, there are multiple threads running, but not exposed. There is always only 
one thread meant for user code, be it on load or as a response on some external 
action.

But there isn't only one"queue" though. Events get queued and dry for execution 
in a certain order, but this order isn't fixed.
 
I hope that helps in addition to what Ravi has said.

-- 
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 nodejs+unsubscr...@googlegroups.com.
To post to this group, send email to nodejs@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/58854691-2272-4e6f-bf08-fccecbad2740%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Re: Error handling philosophy, when should you cb(err), cb(err, object) or cb(null, object) for non-success conditions

2015-05-17 Thread zladuric
In addition to what Aria has said, I also think that encapsulating your 
reponse into an object with `sucess` is not that well.

When writing a package, try writing API specs first, if not tests. For 
example, this is what I'd expect.:

var api = require('my-cool-social-api-module');
api.getPosts(req.user._id); // no callback. ignored.
api.getPosts(null, callback); // no userId. I would expect callback 
with error. Maybe not common Error, but custom, so I can test with err.name 
=' MyApiError', err.message = 'Missing params.'.
api.getPosts(req.user._id, callback); // If I cannot get a response 
from YOUR API, I'd expect an error. I don't care about HTTP statuses at 
this point.

In any case, I would want normalized all errors as much as possible. Then 
when _I_ write _my_ error handling from this module, I can be simple and 
straight-forward:

function callback(err, result) {
  if (err) {
if (err.name === 'ValidationError') {
  // do one thing
} else if (err.name === 'CoolApiError') {
 // your module failed
} else {
 // third party error, if you need to pass it at all.
}
}

It may also be useful, if you're extending Error, to include something like 
err.errorCode alongside err.name and err.message. Then when I message you 
on twitter for a quick help, I have more then 'Server error'.


On Sunday, May 17, 2015 at 12:36:41 AM UTC+2, Owen Allen wrote:
>
> There's a lot of blog posts around the internet talking about the 
> mechanics of handling errors, be it domains or 
> process.on("uncaughtException"). I can't find much definitive talk about 
> the philosophy of error handling though. Specifically when should a 
> function return an error cb(err), or return an error state such as cb(null, 
> { success : false, message : "Some useful message", resp : httpResponse }).
>
> In example, lets imagine we're creating a social media NPM package which 
> has an async function which queries a social media API via an HTTP call 
> using the popular request module and returns some posts. Our function takes 
> 3 arguments a userid and a count and a callback. There are a variety of 
> exit scenarios for this function:
>
> 1. Malformed arguments sent to the function such as a missing cb or a 
> null/undefined/incorrectly formatted userid.
> 2. Unable to reach the service via HTTP.
> 3. Service returned a non-200 status code for some reason, maybe we're 
> being rate-limited.
> 4. Reached the service, but the call failed at the service due to invalid 
> parameters, some services return a 200 status code for this type of failure 
> other's return a non-200 status code.
> 5. Reached the service, the call succeeded but returned an empty array of 
> posts.
> 6. Reached the service, the call succeeded and returned data.
> 7. The function throws an unhandled error due to programmer mistake.
>
> Usually my philosophy for handling errors in this case would be:
>
> 1. cb(new Error("Invalid parameters, must pass a callback"));
> 2. cb(err); // the error that was returned by the http request
> 3. cb(null, { success : false, message : "Service returned a " + 
> resp.statusCode + " status code", resp : resp });
> 4. cb(null, { success : false, message : serviceResponse.message, resp : 
> resp });
> 5. cb(null, { success : true, data : [] });
> 6. cb(null, { success : true, data : posts });
> 7. Whoops, let error bubble up to the application employing our package 
> and it will handle it or crash.
>
> That's just one way to approach the problem. It could be argued that cases 
> 1 - 4 should all cb an error and that the error object should be packed 
> with the additional data to help debug or be a custom error type. Yet at 
> the same time some people argue it's a bad idea to pack additional 
> non-standard keys on to Error objects because it results in inconsistency 
> between Error objects and modules. If every npm module packed it's Error 
> objects with custom keys wouldn't we end up in a pretty chaotic situation? 
> In addition, if that error is thrown or console.error() those extra keys 
> will not show up because of the native behavior of 
> Error.prototype.toString(). 
>
> Yet another approach would be for 1 - 4 to return an error AND the 
> additional data. Such as cb(new Error(serviceResp.message), { success : 
> false, message : serviceResp.message, resp : resp }). This way downstream 
> modules have the useful debugging information available, but we still end 
> up treading down the error pathway of control flow structures such as async 
> and promises. In example, in async if an error is returned it 
> short-circuits all the way to the end.
>
> Any guidance on this subject?
>

-- 
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 

[nodejs] Re: Authentication on different subdomain

2015-05-12 Thread zladuric
Two things.

1. cookieParser is commented because in the present state it's not a 
middleware, just a function that returns one (I think, didn't check it).
If you used `app.use(cookieParser());` instead, I believe you would get 
your cookie.

2. Auth - you have the app.use(session()); in there. This is why your auth 
works. Basically, session will read it's own cookie, even if you don't 
parse it for other stuff, like reading data in your request (you shouldn't, 
anyway).

On a side note, you might want to consider removing cookies completely - 
just return an auth-token on login response instead of session and cookies. 
Then the client only has the token and you don't manage client state. There 
is even passport stuff for this.

On Monday, May 11, 2015 at 7:58:21 PM UTC+2, joel wrote:
>
> I am working on existing code base that someone else wrote. it's 
> Angular+Node.js.
> I am trying to split it into 2 apps - serving angular with nginx and API 
> service using Node.js.
>
> I have nginx as a reverse proxy. the angular is running on port 3001 and 
> the API on 3000.
> The problem is after a successful login (using passport local strategy), 
> the next API is being called with no cookie in the request (I see it in the 
> chrome console).
> Afret reading https://github.com/jaredhanson/passport/issues/12 I added .
> my-site.com to the express session middleware but it's still not working. 
> any tips?
>
> Thanks!
>
> var express = require('express');
> var favicon = require('serve-favicon');
> var logger = require('morgan');
> // var cookieParser = require('cookie-parser')
> var bodyParser = require('body-parser');
> var session = require('express-session');
> var allowCrossDomain = require('./allow_cross_domain.js');
> var app = express();
>
> // middelwares
>
> // app.use(cookieParser);   // i am not sure why it's commented. if i 
> uncomment this things don't work.
> app.use(bodyParser.json());
> app.use(bodyParser.urlencoded({ extended: false }));
> app.use(session({secret: 'sBio', cookie: {maxAge: 432, domain: '.
> my-site.com'}, resave:false, saveUninitialized:false}));
> app.use(allowCrossDomain);
>
> // routes
> ...
> ...
> ...
>
>
>

-- 
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 nodejs+unsubscr...@googlegroups.com.
To post to this group, send email to nodejs@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/669774aa-3433-4fd9-a177-56228c456caa%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Re: Do I need cookie-parser?

2015-05-12 Thread zladuric
Everything is working fine because most likely you're using a session 
middleware with passport which reads cookies on its own.

So if you don't need to store other data in the cookies, that's fine and 
you can go on without them.

On Tuesday, May 12, 2015 at 3:56:18 AM UTC+2, joel wrote:
>
> my express is using passport's local strategy. 
> i just noticed i don't use the cookie-parser middleware and everything 
> seems to work fine. 
> The passport example app have it - 
> https://github.com/mjhea0/passport-local-express4/blob/master/app.js#L26 
>
>
> any ideas?
>

-- 
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 nodejs+unsubscr...@googlegroups.com.
To post to this group, send email to nodejs@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/099c43a5-5037-4498-8ead-9451d15e0df4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Re: We want to solve the callback-hell that exists in calling to Async function in Node.JS

2015-05-07 Thread zladuric
I think you can simply solve this with async, await etc for realworld 
usages. Even Promises, for most cases.

But if you're doing this as a research or learning project, then I'm 
curious.

How do you handle the async stuff in the background? Do you use anything 
from above? How do you manage errors?

On Monday, May 4, 2015 at 5:12:13 PM UTC+2, ami wrote:
>
> Hello everyone.
>
> I thought about a solution how to solve the callback hell.
>
> var a=asyncFunction1(parameters,function(err,param1){
>   var b=asyncFunction2(parameters,function(err,param2){  
>  if (err) console.log(err)
>  console.log('here')
>   }
>
> I want to create new syntax for calling to async functions.
> The new syntax will be as extension to JavaScript (like TypeScript, or 
> CoffeScript but minimalist change to the JS code).
> It will be compiled just before Node.jS running the JavaScript.
>
> I have created new GitHub repository. And I want to start developing it. (
> https://github.com/AminaG/HeavenScript)
> I am searching for other developers, who want to join me in this project.
> I need help in 2 things:
> 1. IDE's intellisense. Because I am changing little bit the JavaScript, 
> all IDE's will create warnings. So I need to create new definition files 
> for them (IntelliJ, SublimeText, VS, etc;) Who here know how to do it?
> 2. Help me with English. My development skills, are much better than 
> English. So for explanations, and create README file, I need help.
>
> //**
> the new syntax:
>
> a=@asyncFunction1(param1)
> err,b=@asyncFunction2(param2)
> console.log('now we can access to a,b')
>
> it will be converted to
>
> asyncFunction1(param1,function(err,a){
>   if(err) throw err; 
>   asyncFunction2(param2,function(err,b){
> console.log('now we can access to param1, param2')
>   })
> })
>
>
> //**
> One More Example:
>
> See how much it is easier and readable to write it in HeavenScript
>
> function theBlock(){
>   a=@asyncFunction1(param1)
>   err,b=@asyncFunction2(param2)
>   console.log('Now we can access a,b,err')
>   if (err) {console.log('error in function2'),
>   err,c=@asyncFunction3(param3) {
>   console.log('Now we can access a,b,c')
>   }
>   d=@asyncFunction4(param4)
>   console.log('Now we can access only to a,b. c is in another scope')
> }
>
> (304 characters)
>
> It will be converted to:
>
> asyncFunction1(param1,function(err,a){
>   if(err) throw err
>   asyncFunction2(param2,function(err,b){
> console.log('Now we can access a,b,err')
> if (err) console.log('error in function2')
>   asyncFunction3(param3,function(err,c){
>  console.log('Now we can access a,b,c')
>   })
>   d=asyncFunction4(param4,function(err,d){
>   if(err) throw err
>console.log('Now we can access only to a,b. c is in another 
> scope')
>  })
> })
> })
>
>
> (391 characters)
>
> What do you think?
>

-- 
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 nodejs+unsubscr...@googlegroups.com.
To post to this group, send email to nodejs@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/533a8c0e-cd93-46ff-89a1-2108fcd0ad68%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Nodejs on managed server

2015-04-21 Thread zladuric
nvm can handle user-specific packages and globals and versions. That would but 
be a problem.

What also well not be a problem, but can produce a neat pile of work is proxy 
stuff. Can you have the provider proxy paths on apache or nginx to your port or 
ports? If it's just one port, then there will have to be some port sharing or 
multiplexing or some such.

-- 
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 nodejs+unsubscr...@googlegroups.com.
To post to this group, send email to nodejs@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/e34b84dc-44b5-4a45-b8d1-39df03aba27f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [nodejs] Re: How to stop tweets from getting duplicated using Socket.io?

2015-04-19 Thread zladuric
Well check for duplicates by the IP:port:client key or something similar.

Also I'm pretty sure you can also listen for client.on('disconnect') on the 
server and remove that client on hard page refresh.

-- 
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 nodejs+unsubscr...@googlegroups.com.
To post to this group, send email to nodejs@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/02678f4d-2e81-4ef0-b6ba-058c63b138e3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [nodejs] Re: Is it a good idea to require regular js-files without absolute path?

2015-04-15 Thread zladuric
You can achieve similar via either a private npm registry or private git 
packages. And several other ways, probably.

If your helpers really are good candidates to be standalone, create a separate 
git repo and add that to package.json as

"dependencies": {

  "express": "*",
  "helper1": "git.repo.url#branch"
}

Then when you require helper1, it is absolute.
HTH

-- 
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 nodejs+unsubscr...@googlegroups.com.
To post to this group, send email to nodejs@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/998c2d12-5e1a-4978-8d21-f6cff880b720%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Re: Losing scope of variable

2015-03-20 Thread zladuric
phantom.create() and then the createPage() are async. That means that by 
the time the interpreter gets to the module.exports section, your _page is 
stil not bound. It only fired a phantom.create, and it's still waiting for 
its callback and phantom.createPage callback. You could probably add a 
console.log('Creating exports') just above creating module.exports and I 
bet that one would be shown before the other two log lines.

Now, you would have to defer creating the exports, or at least put page in 
something like `var locals = {page: }`, and then calling it as 
locals.page.open() later. I think something like that would work.

On Thursday, March 19, 2015 at 9:39:36 PM UTC+1, CoffeeManiac wrote:
>
> I can't figure out why I lose the object instance for my variable _page 
> once it gets inside the function for the module.exports.  It bombs out here 
> because _page is undefined but it's fine and has an instance BEFORE this 
> _page.open 
>
> var phantom = require('phantom'), _ph, _page;
> var should = require('chai').should();
>
> phantom.create("--web-security=no", "--ignore-ssl-errors=yes", { port: 12345 
> }, function (ph) {
> console.log("Phantom Bridge Initiated");
> _ph = ph;
>
> _ph.createPage(function(page) {
> console.log("Page created!");
> _page = page;
> });
>
> phaçntom.exit();
> });
>
>
> module.exports = function() {
> "use strict";
>
> this.Given(/^I visit the episodes display page$/, function (callback) {
>
> console.log("_page: " + _page);
> _page.open("/", function(status){
>
> status.should.equal("success");
> });
>
> callback();
>
> });
>
>
> this.Then(/^I should not see any episodes listed$/, function (callback) {
> //page.should.have.content("There are no episodes available");
>
> callback.pending();
> });
>
>
>
> this.Given(/^there are some episodes to view$/, function (callback) {
> // Write code here that turns the phrase above into concrete actions
> callback.pending();
> });
>
> this.When(/^I go to the episodes display page$/, function (callback) {
> // Write code here that turns the phrase above into concrete actions
> callback.pending();
> });
>
> this.Then(/^I should see a list of episodes grouped by Topic$/, function 
> (callback) {
> // Write code here that turns the phrase above into concrete actions
> callback.pending();
> });
>
>
> };
>
>

-- 
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 nodejs+unsubscr...@googlegroups.com.
To post to this group, send email to nodejs@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/dcb07f98-06e6-4603-b8fe-61da7a66dcc8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [nodejs] Creating an array of key-value pairs(fetched from a mongoDB database) dynamically

2015-03-15 Thread zladuric
Your query is also not optimal.

As I wrote on your SO question, you should do something like this:

User.find({
// setup query
username: {$in: req.user.followed_users}
},
{
// setup fields to return
username: true,
profilepic: true,
userbio: true
  },
  // callback
  function (err, followedUsers) {
res.json(followedUsers); // or render or whatever.
  });
  },

On Saturday, March 14, 2015 at 3:15:26 PM UTC+1, Aryak Sengupta wrote:
>
> Hi Angel,  
>
> Thanks for your reply.I resolved it. What you mentioned in the end is 
> absolutely true. 
>
>
> *"Understanding callbacks/async is the price to pay to live at Node.js 
> paradise ;-"*
> I want to dive in deeper to async callbacks. Can you refer me some 
> resources which will help me to grasp the concept properly. 
>
> Thanks again. 
>
>
>
> On Sat, Mar 14, 2015 at 7:09 PM, Angel Java Lopez  > wrote:
>
>> Hi!
>>
>> I didn't run this code, but maybe is a solution
>>
>> router.get('/account',isAuthenticated, function(req,res){
>>var following_users_details = [];
>>var i = 0;
>>
>>getOneUser();
>>
>>function getOneUser() {
>>
>> var following_user = req.user.following_users[i++];
>> 
>> if (!following_user) {
>> res.render('users/userAccount',{user:req.user, 
>> following_users_details:following_users_details });
>> return;
>> }
>> 
>> User.findOne({'username' : following_user },
>> function(err,user)
>> {
>> if (!err) 
>> following_users_details.push({
>> username: user.username,
>> profilepic : user.photo,
>> userbio : user.bio
>> });
>> 
>> setTimeout(getOneUser, 0);
>> });
>> }
>> });
>>
>> The original code returned a result BEFORE the find one user executes the 
>> callback.
>>
>> The above code retrieves one user, and then, in the callback, invoke the 
>> same function to retrieve another user. It should be better solutions, but 
>> I hope this code works.
>>
>> Understanding callbacks/async is the price to pay to live at Node.js 
>> paradise ;-)
>>
>> Angel "Java" Lopez
>> @ajlopez
>>
>>
>> On Sat, Mar 14, 2015 at 6:55 AM, Aryak Sengupta > > wrote:
>>
>>> *I am trying to create an array of Key-Value pairs dynamically with a 
>>> document from a MongoDB database .* 
>>>
>>> I have posted my question on Stack Overflow but still I can't figure out 
>>> where I am going wrong. This is my question ->
>>>  
>>> *Creating an array of key-value pairs(fetched from a mongoDB database) 
>>> dynamically* 
>>> 
>>>
>>> Any help will be appreciated, 
>>> Thank You. 
>>>
>>> -- 
>>> 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 nodejs+un...@googlegroups.com .
>>> To post to this group, send email to nod...@googlegroups.com 
>>> .
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/nodejs/CALTbq1w%2B5Wz-RWmtSWADc%3Dn%2BF9tP4aYOqs-_S%3D7jbeBaawerKg%40mail.gmail.com
>>>  
>>> 
>>> .
>>> 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 nodejs+un...@googlegroups.com .
>> To post to this group, send email to nod...@googlegroups.com 
>> .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/nodejs/CAMs%2BDqK0HCDGPPwt7G4mGXjdtnrRGyhqooQC6P2FhGvMD3YFew%40mail.gmail.com
>>  
>> 
>> .
>> 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/

[nodejs] Re: how to replace function implementation in a module (e.g. for testing)

2015-03-10 Thread zladuric
Your module holds internally to the reference of the internal function. 
Furthermore, it doesn't even know about the external one.

So it means your doSomethingElse needs to address the proper function 
reference, like override the prototype or use some closure object.

You can try something like this:

`myMod.js`

function doSomething() {

   console.log('internal');
}
function callSomething() {
obj.doSomething();
}
var obj = {

   doSomething: doSomething,
   callSomething: callSomething
};

module.exports = obj;


Module usage:

zlatko@localhost:~/tmp$ node
> var m = require('./mod')

> m.doSomething()
internal

> m.callSomething()
internal

> m.doSomething = function() {console.log('external');}
[Function]
> m.callSomething()
external


The alternative would be that you override the module prototype once you 
load it.

Zlatko


On Monday, March 9, 2015 at 4:39:58 AM UTC+1, MC wrote:
>
> Hello,
> I'm trying to override function implementation where original function is 
> part of nodejs module (myMod.js):
> 'use strict';
> function doSomething(req,res) {
>  console.log('internal');
> }
> function doSomethingElse(req,res) {
>  doSomething(req,res);
> }
> module.exports.doSomething=doSomething;
>
> I can override doSomething from the outside:
> var myMod = require('myMod.js');
> myMod.doSomething = function(req,res) {
>  console.log('external');
> };
>
> And when I call doSomething new implementation is used (prints 'external').
> But when I call doSomethingElse it still prints 'internal' - it looks like 
> inside the module original implementation is used.
>
> I saw a post that suggested declaring a variable (inside module):
> var doSomehing = module.exports.doSomething = doSomething;
>
> But using that didn't help.
> Any suggestions on how to replace doSomething so that calling 
> doSomethingElse prints 'external'?
> Thanks,
>
> M
>
>

-- 
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 nodejs+unsubscr...@googlegroups.com.
To post to this group, send email to nodejs@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/b2c86f2e-daeb-4a08-a0fe-3352794c7336%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Re: How do I change the tracking keyword for a twitter stream using the app.get()

2015-03-05 Thread zladuric
Hi,

This is going to be a two-step process for you. Your app now does two 
things:
1. Track tweets and save them to DB.
2. On rendering Index page, displays those tweets.

You want to change the following:
- change the tracking keyword based on url
- fetch only such keyworded tweets.

The first part is simple.

Instead of the part:

app.get('/', routes.index), you will have app.get('/:keyword', 
routes.keywordIndex);

And the routes.keywordIndex is a function that starts loading only 
functions by that keyword
You will have to alter the tweet model slightly:
- add a 'keyword' property (and save it from that nTwitter stream, along 
with tweet data).
- add a keyword parameter to Tweet.getTweets that will only search such 
tweets. (And take it into account with paging.

Then alter the bottom part of server.js - instead of starting to fetch 
right away, put the twit.stream(...) in a function that will take a 
keyword. It will only start running (fetching stream) as you call this 
function from route handler.

I think that nTwitter can only be used for one stream given one API key, 
but not sure on that. Check it yourself, and if it's true, this will be a 
single-user app :)

Here, I've given you one possible plan, but it's on you to start hacking 
into details, and hit stackoverflow when stuck.



On Tuesday, March 3, 2015 at 5:45:22 PM UTC+1, Aryak Sengupta wrote:
>
> Any kind of help would be appreciated. I need to know whether I am moving 
> in the right direction. Is it the way to do it? Or am I doing something 
> terribly wrong. If my question needs further clarification, then please let 
> me know. I'll try to phrase my question in a different manner. 
>
> Thanks :) 
>
> On Tue, Mar 3, 2015 at 12:59 PM, Aryak Sengupta  > wrote:
>
>> Hi everyone, 
>>
>> I am new to Nodejs and Socket.io. I have worked through a tutorial which 
>> describes how both the technologies work together. 
>>
>> *The link to the tutorial is this :--- >  Build a real-time Twitter 
>> stream 
>> 
>>  and 
>> the code **for the tutorial **is posted at github :---> Code of 
>> react-tweets . *
>>
>> Everything works fine in the tutorial and I also have no issues in 
>> understanding the code since the code is well commented.
>>
>>
>>
>> * In the server.js file, the tracking keyword which is "javascript" is 
>> manually fed into the "twit" object. i.e. here is the code for it. *
>> *twit.stream('statuses/filter',{ track: 'javascript'}, function(stream){*
>> *  streamHandler(stream,io);*
>> *});*
>>
>>
>>
>> *But I want to make a minor alteration in the code to make the 
>> application a bit more versatile. I want to change the tracking keyword 
>> dynamically using the URL entered by the user.*For example, if the URL 
>> entered is *http://localhost/football *, then 
>> automatically I want the track keyword to be changed to "*football*". 
>> The code should look like 
>>
>> *twit.stream('statuses/filter',{ track: 'football'}, function(stream){*
>> *  streamHandler(stream,io);*
>> *});*
>>
>> Now, I tried to set this object inside the *app.get("/cricket", 
>> twit.stream...); *function but I get an error "Expected callback got 
>> object" . 
>>
>> How do I change the above mentioned code to achieve this?. Please let me 
>> know. 
>>
>> Thanks a lot. 
>>
>>
>

-- 
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 nodejs+unsubscr...@googlegroups.com.
To post to this group, send email to nodejs@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/517362b9-c36c-4cab-954b-a75f884447c7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Re: local npm server or git repo server

2015-03-05 Thread zladuric
You can access your own packages from custom git repos in package.json.

For example, I have:

"dependencies": {
"express": : "~4.11.1",
"my-package": 
"git+ssh://g...@bitbucket.org:my-org/my-package.git#branch",

}

npm install/update will update these each time, I think. You can hit 
specific branches, tags or refs with #ref part at the end, or just use 
master.

>From then on, use it as normal packages:

var package = require('my-package');

Zlatko

On Tuesday, March 3, 2015 at 5:46:39 PM UTC+1, AaronNGray wrote:
>
> Hi, 
>
> I have two possible requirements :- 
>
> 1) A local NPM server that I can run on my Windows machine without 
> needing to download and store all NPM packages, that will allow me to 
> override specific packages with my own GitHub packages. 
>
> or 
>
> 2) The ability to refer to either GitHub or local packages or both in 
> package.json files. 
>
> Many thanks in advance, 
>
> Aaron 
>

-- 
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 nodejs+unsubscr...@googlegroups.com.
To post to this group, send email to nodejs@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/90fc18a4-3895-4442-9f2c-d95588c48023%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Re: Cannot comprehend module-based inheritance and composition

2015-03-03 Thread zladuric
Your words and code differ a bit, but this is not a problem. But the most 
beautiful thing, you don't attempt to do anywhere what you say you want.

You say you want ServerController to inherit from Server and to do it, uyou 
require it in the module. Then later on you instantiate the server and 
attach env. That way it will never work. What you do in server 
instantiation (adding that ENV) is not yet available at the time you start 
the controller module.

The modules are executed at require time. But your actual objects are 
instantiated later from those prototypes (which do not yet have ENV).

Why don't you simply 'init' both with ENV there? The name suggests you 
won't be altering it. Or if you do want to share access to the same ENV the 
way Java does, it's simpler to just have some getter and setter on the 
server so that ctrl can reach for it, or the other way around. Or make a 
better use of class/object/inheritance pattern so that you can use 
something like super().ENV from controller. But it's not how it's usually 
done in node.

To get more details, you should share more of the requirements - why do you 
want to share these? Why do you need to separate them completely from one 
another, but have them share the ENV? Do you need that ENV to also be 
writable? By both server and ctrl?






On Monday, March 2, 2015 at 5:15:09 AM UTC+1, Aaron Martone wrote:
>
> Sorry in advance, I've been at this problem for 6 days now and have failed 
> at every single turn on what I need to do. I simply cannot afford to waste 
> more time, so I'm asking for help.
>
> My directory structure looks like this:
>
> /root
> /controllers
> server.ctrl.js
> /libs
> /classes
> Server.js
> ServerController.js
> server.app.js
>
> I am trying to create a "Server" class based on /libs/classes/Server.js. 
> When instantiated, it takes 1 param, the constant ENV (environment), which 
> is stored in its THIS scope. 
> One of the properties of the "Server" object is called 'ctrl' and that 
> should be set to an instance of the 'ServerController' class at 
> /libs/classes/ServerController.js
>
> The 'ServerController' needs to inherit via the prototype chain, the 
> properties on the 'Server' so that it can gain access to the 'THIS' scope's 
> 'ENV' when it references 'this.ENV'.
> I have tried everything I can think of, many times 20x over, and cannot 
> figure out how this is done. Hopefully I have explained my situation well 
> enough. I'm able to do inheritance without modules, but something about 
> Node's module exporting is throwing me off my understanding.
>
> *FYI*. The ServerController 'class' requires the /controllers/server.ctrl 
> module which exports an object of functions that the ServerController class 
> returns as direct functions off itself. Since ServerController gets stored 
> in the Server object's 'ctrl' property, I was hoping I could call it via 
> Server.ctrl.functionName();
>
>
> *==*
> *FROM HERE BELOW ARE THINGS I'VE TRIED, NOT NECESSARY TO THE QUESTION*
> *==*
>
>
>
> *in server.app.js:*
> var Server = require('./libs/classes/Server'); // the 'Server' class.
> var ServerController = require('./libs/classes/ServerController'); // the 
> 'ServerController' class.
>
> var ctrl = new ServerController();
> var server = new Server(ENV, ctrl);
>
> *in Server.js*:
> function Server(ENV, ctrl) { this.ENV = ENV; this.ctrl = ctrl; }
> Server.prototype.test = function() { console.log('Server-level test'); }
> module.exports = Server;
>
> *in ServerController.js:*
> var Server = require('./Server');
> function ServerController() { }
> ServerController.prototype = Object.create(Server.prototype);
> ServerController.prototype.test = function() { 
> console.log('Controller-level test, shadows Server-level'); }
> module.exports = ServerController;
>
> *Then I try to run things like:*
> server.test(); // Expecting 'Server-level test'
> server.ctrl.test(); // Expecting 'Controller-level test, shadows 
> Server-level');
>
> But I'm running into tons of errors.
>

-- 
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 nodejs+unsubscr...@googlegroups.com.
To post to this group, send email to nodejs@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/a3bd882a-24d4-4e2e-924f-bdbfb9d84b8e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Re: learning javascript or jumping straight to Node.js

2015-02-20 Thread zladuric
The most efficient way to learn Node.js is to do something with it. Nice of 
you to do the research first, very smart!

There are two approaches to this:

1) Try to build something "real".
If you have prior programming experience, you'll know that the language has 
it's quirks. Watch Douglas Crockford "the good parts" if you haven't 
already, to figure out basic gotchas that will stop you, then go straight 
into a project.
It doesn't matter what, as long as it's relatively simple. Maybe a simple 
website that displays a form or two and loads and saves this from the 
database, maybe a command line program that converts a .csv into an xml or 
json.
Then build on that program, expand it or make a new one. Try to build 
something that you've already built with the language you're currently 
using.

2. Do some "boring work" first
Still with Node, only focusing more on general programming concepts. I 
would recommend this if you didn't do any coding before.
Take something like this list here (just something off of Google):
http://www.programcreek.com/2012/11/top-10-algorithms-for-coding-interview/
Go ahead, try it, pick one and do it right _now_. And try to make two more 
today, and then another three tomorrow. (Granted, it's meant Java, but you 
can work on those things with JavaScript just fine. It will teach you a lot 
about syntax, and a about JavaScript specifics.)

The first will get you a little closer to Node.js typical usage sooner. The 
second approach will teach you more about JavaScript sooner.
But if you want to get good at any of this, you should know both JavaScript 
and Node.js specifics well.


But the rewards?

The reward is that you can, once you get good at it, deliver complex REST 
APIs in a week or two, something that would take three people 2 months 
until very recently, and even now it would take a lot in many other 
languages and platforms.
The reward is that you feel the expressiveness of JavaScript, that you feel 
that you can take any library and bring it about and make it suit you just 
perfectly. 
The reward is that you can think much more about the problem at hand, then 
about which library to use and is it compatible with some other library.
The reward is that even after years of Node.js work, you still feel excited 
like a kid on each new project because you get to try and learn new stuff.

That's a humble advice that I feel would be good for myself, and I hope it 
also helps you.

Zlatko




On Tuesday, February 17, 2015 at 3:12:29 AM UTC+1, Kevin Bueno wrote:
>
> Ive done a lot of research, and I want to know what you y'all think? I 
> understand the advantages of already knowing JavaScript, but is it worth 
> the time to put into it?

-- 
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 nodejs+unsubscr...@googlegroups.com.
To post to this group, send email to nodejs@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/842ba8c6-9212-496a-8cfb-82d8817a27fe%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Re: How to check user has logged in before every request - node.js

2015-02-14 Thread zladuric
I tend to use token-based auth, but you can also use cookies to keep your 
users' sessions..

The principle is the same: hook a "middleware" function into the app, into 
the request, that checks if the user is logged in.
If yes, usually it will add a 'user' object with more info to the request.

Now, usually you don't do it on your own, something like passport.js is 
what people would use for this purpose.


On Thursday, February 12, 2015 at 1:43:13 PM UTC+1, prem Kumar wrote:
>
> Hi,
>
> Need to check whether the user has logged-in or not with session before 
> every page request.. Please guide me to solve this issue..
>
>
>
>
> Thanks,
> Premkumar M.
>

-- 
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 nodejs+unsubscr...@googlegroups.com.
To post to this group, send email to nodejs@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/ae865558-a325-42d8-bcaa-cad8e669c2fb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Re: install a package on an offline pc with npm

2015-02-12 Thread zladuric
If you have npm 2+, I think `npm link` would work.

Download the package, offload it something, like /opt/npm/my-package.
Add it to dependencies ("my-package": "1.0.0")
Then npm link to that package (`npm link /opt/npm/my-package).

-- 
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 nodejs+unsubscr...@googlegroups.com.
To post to this group, send email to nodejs@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/5678e404-8b06-454b-9014-4c7a95c04773%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Support plugin system in Node.js

2015-02-03 Thread zladuric
Of course you can, it's just the question of how integrated you want it to be.

Take a look at mean.io project, as far aI remember, they had just that.

There are others, too, and you can build your custom plugins for your 
architecture.

Depends a bit oh what you have right now and what exactly you want.

-- 
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 nodejs+unsubscr...@googlegroups.com.
To post to this group, send email to nodejs@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/e42aab25-2d79-4117-aa2b-680d1bfdbfbf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Re: Get HTTPS response outside of the current function

2015-01-07 Thread zladuric
I assume you're trying to make a synchronous call from a node.js script, 
then when it finishes, do other things as well.

If your other scripts are also node.js, you would probably add a `callback` 
parameter to your _call method, and call it when done.

Example:

function _call(cb) {

  request.get(someUrl, function(err, response) {
// handle err if any 
if(err) {return cb(err);}

// do stuff with body, i.e. your JSON.parse
// then call the callback
cb(null, response.body);
  });
});
// then export the function
module.exports.call = _call;

You would call this as follows, from other modules:

var myModule = require('./linode-module.js');
// when you call the module, pass it a function that will be executed 
when done. That is where you get the results.
myModule.call(function(err, body) {

// this function will receive your response.
console.log(body);
// now you can do other useful things with it.
});


Hope that helps.

Zlatko


On Wednesday, January 7, 2015 1:05:42 AM UTC+1, Tiago Hillebrandt wrote:
>
> Hey guys,
>
> I need to do an HTTPS request to the Linode API.
>
> That said, I am looking if would be possible to return an HTTPS response 
> as value on this function: http://paste.ubuntu.com/9684987/
>
> I tried some specific things to make the thread wait until request ends, 
> like *setTimeout()* and *while (!req.finished) {}*, but nothing seems to 
> work as expected.
>
> This is my first Node.js implementation, so I am not sure if this would be 
> the better way to perform this action.
>
> Do you guys have any suggestions on this?
>
> Thanks in advance!
>
>
>

-- 
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 nodejs+unsubscr...@googlegroups.com.
To post to this group, send email to nodejs@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/ca4f3548-b1bf-4d45-a388-b5cdb722c8d5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [nodejs] NPM and sudo

2015-01-06 Thread zladuric
Technically, sudo npm isn't running as root. It's running as that user, but 
with root privileges. Do files get written as the user to, say, /usr/local.

Personally, from my humble 18 year linux experience, I would not install just 
anything into /usr/local, only battle tested stuff. Sometimes you have to, but 
avoid it on production if possible. Most anything you would usually use on a 
internet site, production box, should use it's own user, not root, and have 
majority of deps be either local (like your code or npm modules) or very well 
tested (like pm2). 

-- 
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 nodejs+unsubscr...@googlegroups.com.
To post to this group, send email to nodejs@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/4f68c460-6aca-4ad1-a141-516e118f198d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Re: Failed to lookup view

2015-01-05 Thread zladuric
It seems like you're missing 500.handlebars (or maybe .hbs) error message 
in "d:\projects\meadowlark\site\views".

Do you have a 500.* file anywhere in your app? If yes, did you point your 
views directory somewhere else then default? If yes, maybe put a 
500.handlebars in the views/ dir.

If not, lookup somewhere on the net for an example or to be quick about it, 
put this in d:\projects\meadowlark\site\views\500.handlebars:

{{error}}


Then, as Ryan here says, you'll have to find your actual error, but that's 
another question :)




On Sunday, January 4, 2015 9:23:01 AM UTC+1, sachin tiwari wrote:
>
> Hi, 
>
> I am beginner to node.js. I am working with an example here with and I am 
> using 'handlebars'. But I am unable to load view of pages. I have kept my 
> pages inside views folder but I am not able to see results.
>
> I am getting error.
>
> Error: Failed to lookup view "500" in views directory 
> "d:\projects\meadowlark\site\views"
>at EventEmitter.app.render 
> (d:\projects\meadowlark\site\node_modules\express\lib\application.js:519:17)
>at ServerResponse.res.render 
> (d:\projects\meadowlark\site\node_modules\express\lib\response.js:904:7)
>at d:\projects\meadowlark\site\meadowlark.js:29:7
>at Layer.handle_error 
> (d:\projects\meadowlark\site\node_modules\express\lib\router\layer.js:58:5)
>at trim_prefix 
> (d:\projects\meadowlark\site\node_modules\express\lib\router\index.js:269:13)
>at 
> d:\projects\meadowlark\site\node_modules\express\lib\router\index.js:238:9
>at Function.proto.process_params 
> (d:\projects\meadowlark\site\node_modules\express\lib\router\index.js:313:12)
>at 
> d:\projects\meadowlark\site\node_modules\express\lib\router\index.js:229:12
>at Function.match_layer 
> (d:\projects\meadowlark\site\node_modules\express\lib\router\index.js:296:3)
>at next 
> (d:\projects\meadowlark\site\node_modules\express\lib\router\index.js:190:10)
>
> Please help me regardng this to solve it.
>
> My js code is as follows:
> var express = require('express');
> var app = express();
> // set up handlebars view engine
> var handlebars = require('express3-handlebars')
> .create({ defaultLayout:'main' });
> app.engine('handlebars', handlebars.engine);
> app.set('view engine', 'handlebars');
>
> app.set('port',process.env.port || 3000);
>
> app.get('/', function(req, res) {
> res.render('home');
> });
>
> app.get('/about', function(req, res) {
> res.render('about');
> });
>
> // 404 catch-all handler (middleware)
> app.use(function(req, res, next){
> res.status(404);
> res.render('404');
> });
>
> // 500 error handler (middleware)
> app.use(function(err, req, res, next){
> console.error(err.stack);
> res.status(500);
> res.render('500');
> });
>
> app.listen(app.get('port'),function(){
> console.log('Express started on http://localhost: '+ app.get('port') + " 
> Press CTRL+C to terminate.");
> });
>
>
> Thank you,
> Sachin
>

-- 
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 nodejs+unsubscr...@googlegroups.com.
To post to this group, send email to nodejs@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/b0fa5834-4410-4a71-9a4d-c290ecaed125%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [nodejs] Re: js-git

2014-12-31 Thread zladuric
If it is solving your problem you want to achieve, did you hear about gitlab? 
Good a full github-like solution. If it is simple serving of repos, there are a 
few tutorials on the net about nginx for this.

If you want to solve the issue with node and JavaScript though, then I guess 
best bet is to clone js-git and continue where it stopped.

-- 
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 nodejs+unsubscr...@googlegroups.com.
To post to this group, send email to nodejs@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/fbb6008d-c4ac-4ad6-ba5e-fc5cca9b17a7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Code checker

2014-12-31 Thread zladuric
I use jhint, jscs and I'm starting to add istanbul to my projects. I feel my 
code quality is much better for it.

Just the first two should do a lot for you, testing and code coverage will take 
you further.

-- 
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 nodejs+unsubscr...@googlegroups.com.
To post to this group, send email to nodejs@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/f7d9ad3c-3053-42ef-a8cf-ecef4b2d3cfe%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Re: which framework to use (express, meteor or koa)

2014-12-21 Thread zladuric
With your "skill level: beginner", I would definitely recommend Express. 
Koa is not out-of-the-box ready on a typical node installation, and all 
others presume that you have previous knowledge of the framework itself.

And you would end up having to learn more then just Node.js, usual 
patterns, javascript specifics, you would also get confused by the 
framework "magic".

Express is very distributed, well documented, lots of examples, lots of 
questions you will have already answered on Stackoverflow. Besides that, 
once you pass a mandatory tutorial or two online (pick anything, I suggest 
one of the video tutes),  you won't have to remember everything from that 
tutorial. After a few basic things, Express is pretty forgiving and you can 
make all beginner mistakes right away, and then fix them and work on them 
as your skill grows.

Zlatko

On Saturday, December 20, 2014 4:27:18 PM UTC+1, Roelof Wobben wrote:
>
> Hello,
>
> I want to try to make a financial app in node,js by using a web frameworks.
>
> As far as I can see there are a few I can use like meteor, express or koa. 
>
> Which one can I use the best and why ?
>
> Roelof
>
>

-- 
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 nodejs+unsubscr...@googlegroups.com.
To post to this group, send email to nodejs@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/2c68eb49-0fc1-4cf3-a62b-fd83984d9fd1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [nodejs] Nodejs randomly hitting 100% CPU

2014-12-19 Thread zladuric
Also, do you at least know where in the code is this happening?

100% CPU suggests there might be a blocking bit of code. There are very 
simple modules, things like 
[blocked](https://www.npmjs.com/package/blocked), that might help you 
locate the critical part, if not already, so you might to observe and test 
this code?


On Wednesday, December 17, 2014 4:23:52 PM UTC+1, Alain Mouette wrote:
>
>  Maybe if you run node with *nice* (in Linux) you could run some other 
> higher priority command...
>
> Enviado através do AquaMail para Android
> http://www.aqua-mail.com
>  
> A 17 de dezembro de 2014 12:56:03 Karim Tarek  > escreveu:
>
> The problem is that @ 100% cpu anything installed like node or via npm 
> like new relic doesn't even respond/report during the 100% cpu time. Its 
> like the application froze, nothing working inside of node i tried using 
> the usage module to try to restart node but it didn't work! any other 
> suggestions ? and concerning the npm v8 profiler how would i start 
> profiling from outside node i mean from the cmd because as i just said the 
> node app is not responding during the 100% cpu time
>
> On Wednesday, December 17, 2014 4:26:42 PM UTC+2, Fedor Indutny wrote:
>
> Please consider using some module like: 
> https://www.npmjs.com/package/v8-profiler , to enable and disable 
> profiling in runtime, without logging everything.
>
> So just wait for the 100% CPU peak and turn on profiler for a couple of 
> seconds.
>
> On Wed, Dec 17, 2014 at 9:09 PM, Karim Tarek  
> wrote:
>
> Hi Fedor!
>
> Thanks for the reply! i wanted to tell you that i already tried profiling 
> and started node with the --prof parameter but what happened is the 
> following a log file was created for each process and it kept increasing in 
> size like crazy in like 4 hours the file size reached 1.9GB so is there any 
> way to profile the node app at the spike time only in order to be able to 
> process it via the node-tick-processor ? because when i tried to read the 
> 1.9GB file it ran out of memory while reading it and i tried to split but 
> the context was lost so any suggestions? 
>
> On Wednesday, December 17, 2014 3:55:03 PM UTC+2, Fedor Indutny wrote:
>
> Hello Karim,
>
> I'd suggest profiling the application during such spikes. It seems that 
> the app is spinning in JS and doing lots of allocations (because of mmap() 
> calls in strace output).
>
> Cheers,
> Fedor.
>
>
>
> On Wed, Dec 17, 2014 at 5:03 PM, Karim Tarek  
> wrote:
>
> We are facing a problem with our Node js (v0.10.33) application with 
> CLUSTER module on ubuntu amazon EC2 (c3.large) instance that nearly 
> everyday we get a 100% cpu spike (on the workers) suddenly and it never 
> goes down until we restart our application the problem is that these spikes 
> happens randomly and at weird times (at 3AM) when the traffic is minimal, 
> when i looked at the logs i found that the logs and any APMs stopped 
> recording any requests probably because the node js app stopped working, 
> what i did based on what i read so far is that i did a strace on the 
> process which was at 100% and here is a part of the output of my stack 
> trace (full strace attached): 
>
> gettimeofday({1418314214, 491214}, NULL) = 0
>
> gettimeofday({1418314214, 491327}, NULL) = 0
> futex(0x7faad80008c8, FUTEX_WAKE_PRIVATE, 1) = 1
> gettimeofday({1418314214, 619975}, NULL) = 0
> gettimeofday({1418314214, 620055}, NULL) = 0
> futex(0x7faad80008c8, FUTEX_WAKE_PRIVATE, 1) = 1
> mmap(0xfcc3b00, 20480, PROT_READ|PROT_WRITE, 
> MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, 
> -1, 0) = 0xfcc3b00
> mprotect(0xfcc3b005000, 4096, PROT_NONE) = 0
> mmap(0xfcc3b006000, 1019904, PROT_READ|PROT_WRITE|PROT_EXEC, 
> MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0xfcc3b006000
> mprotect(0xfcc3b0ff000, 4096, PROT_NONE) = 0
> mmap(0xfcc3b10, 20480, PROT_READ|PROT_WRITE, 
> MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, 
> -1, 0) = 0xfcc3b10
> mprotect(0xfcc3b105000, 4096, PROT_NONE) = 0
> mmap(0xfcc3b106000, 1019904, PROT_READ|PROT_WRITE|PROT_EXEC, 
> MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0xfcc3b106000
> mprotect(0xfcc3b1ff000, 4096, PROT_NONE) = 0
> gettimeofday({1418314214, 731602}, NULL) = 0
> gettimeofday({1418314214, 731682}, NULL) = 0
> futex(0x7faad80008c8, FUTEX_WAKE_PRIVATE, 1) = 1
> mmap(0xfcc3b20, 20480, PROT_READ|PROT_WRITE, 
> MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, 
> -1, 0) = 0xfcc3b20
> mprotect(0xfcc3b205000, 4096, PROT_NONE) = 0
> mmap(0xfcc3b206000, 1019904, PROT_READ|PROT_WRITE|PROT_EXEC, 
> MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0xfcc3b206000
> mprotect(0xfcc3b2ff000, 4096, PROT_NONE) = 0
> gettimeofday({1418314214, 835071}, NULL) = 0
> gettimeofday({1418314214, 835154}, NULL) = 0
> futex(0x7faad80008c8, FUTEX_WAKE_PRIVATE, 1) = 1
> mmap(0xfcc3b30, 20480, PROT_READ|PROT_WRITE, 
> MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, 
> -1, 0) = 0xfcc3b30
> mprotect(0xfcc3b305000, 4096, PROT_NONE) = 0
> mmap(0xfcc3b306000, 1019904, PROT_READ|PROT_WRI

[nodejs] Re: Node JS in a virtual environment?

2014-12-14 Thread zladuric
Sa Sachi has said, the only thing you might want to use that's globally 
affecting is the version of Node yourself (like Python 2 or 3).

It's a rare thing, you would usually either use one version, or just update 
it to latest at all times. But if you have a rare need to update that, then 
n or nvm are good solutions: https://www.npmjs.com/package/nvm 
or https://www.npmjs.com/package/n.

Now, with this, there _might_ be an issue of global modules. For example, 
you want to use bower globally. It's doable for most things, but in in an 
unlikely event that you want cli versions of a module, from multiple 
versions of that module, I think it would not work.

So just use n and off you go.

-- 
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 nodejs+unsubscr...@googlegroups.com.
To post to this group, send email to nodejs@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/95212f47-563e-46c9-9042-c3ed2b2d05fc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [nodejs] Sync Videos on separate devices using nodejs

2014-12-06 Thread zladuric

On Saturday, December 6, 2014 6:22:43 AM UTC+1, ryandesign wrote:
>
>
> It would help to see the portion of your code that's not working. For 
> example, tell us where the video files are on disk, and show us the code 
> that's meant to serve them. 
>
>
>
And also how are you emitting this event to the clients - sockets? long 
poll? 

-- 
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 nodejs+unsubscr...@googlegroups.com.
To post to this group, send email to nodejs@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/d47752cd-fa02-46cd-a51d-e42dc86147af%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Re: PHP to node.js

2014-11-20 Thread zladuric
Vasa,

It seems your webserver.js is incomplete? Either that or you forgot to call 
res.end() in there.
>From what I see, you read file names the database? Then read those files? 
What do you want to do with them? Let's say you just want to respond with a 
JSON of the files you found in the directories you queried.

You'd have to make a few changes to webserver.js.

1. in your request handler, you have an `if(err){return;}` block. You 
should do something like `if(err) { res.status(500); res.end(err);}`. That 
would close the request (that is still waiting for you to end it after you 
went to the database).

2. After that if block, you should do something with results.  Like, 
res.json(files);. That would send back the response as  content-type 
application/json and end the request.

Hope that helps.

On Wednesday, November 19, 2014 7:35:12 AM UTC+1, Vasa wrote:
>
> Hello Aria,
>
> Thank you for pointing out the bug. I am new to PHP :).  I fixed it and my 
> PHP is working fine retrieving the data and charting. 
> But i am trying to move the db queries to my nodejs. So that when a 
> request is made, it queries the db and then tries to chart the data. 
> I have attached my node server. Please help me out.   
>  
>
> On Tuesday, November 18, 2014 1:21:53 PM UTC+5:30, Vasa wrote:
>>
>> Hello noders
>>
>> i am trying to generate a chart (using highcharts) with queried data from 
>> Mysql. 
>> I have my data.php file to query the database and create a JSON file. 
>> This JSON file is used by index.php file to draw the chart. 
>> This is not working because the chart is drawn before the sql data is 
>> retrieved. 
>>
>> I am trying to create a nodejs for the same and i assume this is the 
>> solution to my requirement
>>
>> Any advice here
>>
>>
>>
>>
>>

-- 
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 nodejs+unsubscr...@googlegroups.com.
To post to this group, send email to nodejs@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/91248b7e-31ef-4d14-a649-961db80848b0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Re: Are there any plans to deprecate Streams1?

2014-10-12 Thread zladuric
I'm not sure about 'streams1' though, but there are wrappers for it, such 
as https://www.npmjs.org/package/readable-wrap.

I don't think you need to wrap the writable part of the pipeline, since 
most of the issues with original streams were when readable stream starts 
emitting before you can set up a listener.

As for v3 to v2, as far as I'm aware, it should be backwards compatible., 
it's mostly about flowing/non-flowing mode thing.

On Sunday, October 12, 2014 1:30:45 AM UTC+2, q2dg2b wrote:
>
> Hello friends.
>
> I see still there are many modules based on Streams1, when in Node 0.10 
> Streams2 implementation has appeared. Are there any plans about deprecating 
> Stream1 in a far/near future?? If not, will both implementations coexist 
> side by side?? Which should be officially recomended to use, then?
>
> Thanks
>
> P.D: I've seen in several places (
> http://stackoverflow.com/questions/21538812/what-is-streams3-in-node-js-and-how-does-it-differ-from-streams2,
>  
> https://github.com/joyent/node/issues/5860) a "Streams3" implementation 
> for Node 0.12, but I don't get the point...will it be a real change from 
> Streams2 or is it only a marketing name??
>

-- 
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 nodejs+unsubscr...@googlegroups.com.
To post to this group, send email to nodejs@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/cbc6f459-3b13-472f-b874-663e84d8e87a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Re: request opinions on Node

2014-09-26 Thread zladuric
Oh dear, he asks a bunch of devs on opinions! Good luck with that spam :)

On topic, one of the great things with Node is not so much technical gains, 
as business value. With Node.js and tools, you can make practically hourly 
changes. You can assemble, test and deploy a, say, new dashboard in a day 
and ship it to production. You (in most cases) can't do that with Java, the 
whole cycle is much much slower.

So on the business terms, Node.js is much faster and allows for very fast 
iterations. I think this is important in two groups of users: startups: 
they will have many changes in the product design as they grow. Node is not 
very rigid and allows for this. Corporate users: at least the leaders 
there. They are getting sick of clumsy big Java pipelines and expensive IT, 
as they want results fast. So this is a way to get something out there 
without disturbing anything "important" in the core transactional systems.

That's my two cents after a sleepless night, so don't mind me :)



On Thursday, September 25, 2014 2:57:23 PM UTC+2, Tushar Jain wrote:
>
> Hi Folks!!
>  
> I am about to write an article on what is Node.js and why it is gaining so 
> much popularity in the tech community and the market place. Of course I 
> have tried my best to explain the worth of Node on grounds of the mentioned 
> points. 
> As this is the most active community of node I have found so far, I 
> thought to intake your opinions regarding Node.
> Feel free to give your opinions on why Node is important now a days( or it 
> lacks something that makes it a bad choice for some specific domain).
>  
> Thanks
>  
> Regards
> TJ
>  
>

-- 
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 nodejs+unsubscr...@googlegroups.com.
To post to this group, send email to nodejs@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/aaff63cb-8017-477d-9128-88439a7d7d68%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] worry.... of ES6 and Node & errors

2014-09-10 Thread zladuric
Do you have a source of that data? Because majority of professionals I've 
spoken to and I'm following are eager to start using ES6, done already do.

Especially because it will, implicitly it explicitly, prevent whole classes of 
errors. In any case, I think it is up to the upstream provider of V8, Google.

In any case, you can always remain on node v0.10.x. 

As for documented errors, you're referring to bugs? Did you check github issues 
for node project?

-- 
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 nodejs+unsubscr...@googlegroups.com.
To post to this group, send email to nodejs@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/f7bb8730-dcef-45ff-bd3d-ec936a2618ef%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [nodejs] Re: javascript callback guard - prevents a callback to be called twice

2014-08-22 Thread zladuric

On Friday, August 22, 2014 10:35:29 AM UTC+2, Alisson Cavalcante Agiani 
wrote:
>
> How do people stumble upon this kind of error?
>
>
When you have long and tricky business logic. Ie. I am bidding on a 
product. Make CC authorization. Is it ok? Yes? Go book a product. Did 
somebody in the mean time buy the last one? Remove authorization, or if all 
ok, proceed. What about if my authorization fails? What if I have a retry 
logic on the warehouse check methods because it's unstable?

This can be avoided by not having long methods, having smart architecture, 
but sometimes you inherit messy code, or write it yourself, and you have a 
long long method with multiple possible paths, and in only one of those you 
have to call back.

 

-- 
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 nodejs+unsubscr...@googlegroups.com.
To post to this group, send email to nodejs@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/7d923cfc-990c-4589-8989-de30276f566a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Re: Node.js - Async problem

2014-08-21 Thread zladuric
So, a few problems:

- BLOCKING! 
That's your main issue. Your while() loop with dates is blocking your 
entire app server. It's not like say, PHP where each request gets its own 
instance of a PHP script. Here, one app, one script handles all requests. 
So when you block with while loop, you block all requests and that's why 
your second request is delayed. It's actually executed immediately, but 
immediately after it's been received. Which is after all those milions of 
while loop spins.

That's a very bad practice. You'll also probably notice that your CPU is at 
100% during your long requests.

How to remedy it? Use setTimeout.

So, your userRepository would do something like this:

 getUsers: function(long, callback) {

 if(!long) {

 db.users.find({}, function(err, usersList) {
  
  callback(err, usersList);
 });
 } else {

 setTimeout(function() {

 db.users.find({}, function(err, usersList) {
  
  callback(err, usersList);
 });
 }, 5000);
}
}

Your second issue is method signature, like somebody has mentioned already. 
Your callbacks will usually be the LAST parameter to the request handlers. 
Also, in the callback, you will usually pass err or null as the first 
argument. Say that your db is down - you will want to pass that info and 
your render('index') might look like render('db-error'); instead.

 
On Wednesday, August 20, 2014 3:26:14 PM UTC+2, Дмитрий Папка wrote:
>
> Hello, everyone!
> I am new to Node.Js and not very well understanding the mecanics of 
> callbacks.
>
> I have a MongoDB database installed and running. I have a 'users' 
> collection. In my Node.js (Express) application I want to display a list of 
> stored users.
> I am doing the following experiment: 
>
> var express = require('express');
> var router = express.Router();
> var userRepository = require('../repositories/user_repository.js');
>
> router.get('/:long?', function(req, res) {
> var long = req.param('long');
> long = !!long;
> userRepository.getAllUsers(function(users) {
> res.render('index', {
> users: users
> });
> }, long);
> });
>
> It's a handler for my http://website.com/ URL, which may have an optional 
> URL parameter 'long' I am passing it to my userRepository.getAllUsers 
> method.
>
> userRepository looks like this:
>
> var db = require('../context').db;
>
> var userRepository = {
> getAllUsers: function(callback, long) {
> var now = Date.now();
> var then = now + 5000;
> if (long) {
>  while (Date.now() < then) {}
> }
> db.users.find({}, function(err, users) {
> callback(users);
> });
> }
> };
>
> module.exports = userRepository;
>
> context.js contains only mongoDB settings (username, password, url).
>
> The idea is the following:
>
> If user enters url: http://website.com/, then 'long' parameter will be 
> false and userRepository will just get user list from database and will 
> render to my view.
>
> If user enters url: http://website.com/?long=something, then 'long' 
> parameter will be true and before extracting user list, getAllUsers will 
> 'sleep' for 5 seconds.
>
> With this approach I am trying to simulate a long-time operation (for 
> example, if my users colletion has a lot of documents and we are trying to 
> get them all).
>
> If I am openning: *http://website.com/ *, it loads 
> immediately.
> If I am oppening: *http://website.com/?long=something 
> *, it loads after ~ 5 seconds as 
> expected.
> Now. If I am openning *http://website.com/?long=something 
> * and right after *that 
> **http://website.com/ 
>  - *they both are loading 5 seconds (second request 
> is waiting until the first one will end).
> That means I am doing something wrong, because requests are handled not 
> asyncroniously.
> What did I do wrong?
>

-- 
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 nodejs+unsubscr...@googlegroups.com.
To post to this group, send email to nodejs@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/205b8c08-6da4-4ace-98a0-51e5fb97c718%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [nodejs] nodes js module for desktop apps

2014-07-08 Thread zladuric
So just node.js binary, but packet with your app?

-- 
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 nodejs+unsubscr...@googlegroups.com.
To post to this group, send email to nodejs@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/364a2090-9fda-4c21-bb9f-0f66320b07f3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Re: Java Houses Adopting Node.js

2014-07-02 Thread zladuric


On Thursday, June 26, 2014 10:35:22 AM UTC+2, Adam Davies wrote:
>
> Hi All,
>
> Does anybody know of case studies or have direct experience of a ecommerce 
> companies which have been using Java for many years converting over to 
> node.js?
>
>
LinkedIn is also using Node.js in parts of their stack. Here's the first 
Google link:

http://venturebeat.com/2011/08/16/linkedin-node/

For what it's worth, I have also heard Jeff from Paypal at this years' 
MLOC-JS conference. As I've understood it, they're using Node as a web 
tier, the various heavy-weight backend is still handled in Java and others.

But the takeaway for me there was that they "won over Java on the business 
arguments, not technical" - meaning much much faster iterations over the 
old Java flow and ability to respond to (business) requests and implement 
them daily, almost hourly, over weeks it would take in Java.

There are a few articles of how their prototype was developed in paralell 
with a Java team. What I remember from the talk is that Java team had 7 
people, Node.js had 3, and the Node team was done sooner and their code had 
much more throughput and was even a bit faster then Java, in what they used 
it for.

-- 
Zlatko

-- 
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 nodejs+unsubscr...@googlegroups.com.
To post to this group, send email to nodejs@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/03b374fd-cd1f-42cc-ae25-c6d96aa1c67d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Re: How to write code for routing and route handler's using nodejs(without using frameworks line express/compound)

2014-07-01 Thread zladuric

On Tuesday, July 1, 2014 1:51:01 PM UTC+2, venkat wrote:
>
> I am very new to nodejs and I was searching examples which have code for 
> routing and route handling but can't find. Can I write the code for route 
> handler's without using express.js framework ?, Could you please provide 
> the reference links for routing and routing handler examples using nodejs?
>

Like Nic suggested, take a look at Express/lib/router code. Also, take a 
look at connect: 
 https://github.com/senchalabs/connect/blob/master/lib/proto.js

But put most simply I can make it: your router.js module will register an 
array of valid {URL/HTTP method/handler function} sets, and when the Node's 
built-in 'http' module calls it for each request, it will match url and 
method to execute the appropriate handler.

But put simply, they all take req.pathname that the Node.js builtin 'http' 
module will provide for each request. It's the HTTP path sent by the 
browser.

There are two phases there - setup and later, usage. In the app setup, the 
app starts registering routes, you can think of it as a simple array for a 
simple server:

[
  {
path: '/profile',
method: 'GET',
handler: [Function]
  }, {
path: '/notes',
method: 'GET',
handler: [Function]
  }, {
path: '/notes',
method: 'POST',
handler: [Function]
  }, {
path: '/',
method: 'GET',
handler: [Function]
  }]

So when the app is set up, it now serves requests. Node's 'http' module 
will get each request (and that requests' response object, on which you can 
attach your reply) and give it to your router.
Your router will compare that request with the array. If it matches one, it 
will call it's handler, passing the request and response.

Does any of this make sense to you?

Kind of. At least I think that's the way it works, there are smarter people 
then me here who should do the teaching :)


-- 
Zlatko 

-- 
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 nodejs+unsubscr...@googlegroups.com.
To post to this group, send email to nodejs@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/bb3e7819-4927-496c-ad55-cfc8eec62b89%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Re: Here's your Node.js performance tip of the week - how garbage collection works and how to monitor it

2014-06-26 Thread zladuric
Hi Shubhra,

Very nice, detailed article. It explains the standard GC methods that the 
V8 uses. I've also skimmed

What I'd like to add is a little bit of wisdom I've picked up at the 
MLOC-JS.com conference in Budapest this February. Ben Titzer from Google 
Chrome division was explaining a little bit of this, how does GC work in 
V8, and he's shared a great tip:

create as many objects as you can and just discard them.

They're putting a lot of effort into new-gen optimization - it is a lot 
smaller but a lot faster. When your objects get promoted to tenured 
generation space, then it's a lot more work for V8 to manage them + the 
space size itself is bigger, all of which adds a bit overhead.

So what he has said is not to be afraid to just create as many objects as 
you need and just keep discarding that. 

I guess that translates to "create as many small local scoped vars as you 
need, and V8 will take care of it all".

Or perhaps I've misunderstood it all. 


On Wednesday, June 25, 2014 7:01:16 PM UTC+2, Shubhra Kar wrote:
>
> Coming into Node from a Java background GC always intrigued me. The JVM 
> and CLR have this mastered as a science.
>
> Here is what I discovered for Node and V8. Should be helpful to newbies
>
> http://strongloop.com/strongblog/node-js-performance-garbage-collection/
>
> Kind Regards,
> Shubhra Kar
>
> Product Manager - StrongLoop
>
> *Rapidly **develop APIs* 
> * in 
> Node.js, plus get **DevOps capabilities* 
> * like monitoring, 
> debugging and clustering.*
>

-- 
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 nodejs+unsubscr...@googlegroups.com.
To post to this group, send email to nodejs@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/a416eae0-5d52-4d47-802b-6de01854a846%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [nodejs] Execution Order

2014-04-25 Thread zladuric
Exactly, what Kevin has said.

Replace the whole callback (stuff inside .then() method) with something lke 
this:

app.controller('MyCtrl', function() {
$http.get('/data/url)
.then(someObject);
// and later:
var data = [1, 2, 3];
}

So, what is going on here:

1. http.get gets called.
2. Whatever we get from get(), we call its' then() method. We give it 
''some object'.
3. Data gets assigned. (var data =...)


Now, your $http.get has returned a promise. We have given that promise a 
'callback'. So stuff like:

var myFun = function(response) {/*do stuff*/}
http.get().then(myFun);

is almost the same as

http.get().then(function (response) {/*do stuff */});

In both cases, you're not calling myFun. You're calling .then() and giving 
it myFun as parameter.

So a long long time past that (probably a couple hundred thousand 
nanoseconds :) the get() will receive the response, let's say it calls it 
*response*. When it does, it has your myFun to call with the response. So 
it will do that: myFun(response).

So order of operation:

1. http.get gets called.
2. Whatever we get from get(), we call its' then() method. We give it 
''some object'.
3. Data gets assigned. (var data =...)
4. myFun(response)

Better?

On Saturday, April 26, 2014 5:28:17 AM UTC+2, Kevin Ingwersen wrote:
>
> Because the code with B) is a callback. Its first added to the stack of 
> execution and ran later, which is why variables go out of scope in these 
> cases. So the code 
>

-- 
-- 
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 nodejs@googlegroups.com
To unsubscribe from this group, send email to
nodejs+unsubscr...@googlegroups.com
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 nodejs+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Re: advice on a newcomer, how's the market for nodejs devs? Is it a good field to find remote type jobs/contract?

2014-03-05 Thread zladuric
I am doing freelance work, so here's that perspective: you CAN actually 
find Node.js backend jobs. Rebuild APIs, create MongoDB/Node.js backends 
for mobile devices, things like that.

Of course, most will expect you to do a bit of a frontend, but most of 
Rails jobs will, too (from what I've seen), so you'll have to get on the 
train eventually. Small companies and small teams will mostly look for a 
mixed front/backend work though, yes.



On Tuesday, March 4, 2014 10:53:53 PM UTC+1, gitted wrote:
>
> Hi,
>
> I am looking for some advice from you guys, how's the market right now for 
> nodejs developers?
>
> Any inspirational stories where someone jumped in and was able to break 
> into the freelance market?
>
> I'm into Rails, Java (yes java!) and I have watched a few vids on nodejs 
> and I really like the concept so far.
>
> Is it a tough market to crack b/c you have to be a master of javascript 
> both front end and backend?  I'm not the greatest at frontend type work, I 
> mean I know javascript/jquery but I wouldn't call myself a master who can 
> hackup a single-page gmail type app with ease :)
>
>
>

-- 
-- 
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 nodejs@googlegroups.com
To unsubscribe from this group, send email to
nodejs+unsubscr...@googlegroups.com
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 nodejs+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


[nodejs] Re: Which promises library to use?

2014-02-08 Thread zladuric
I really like https://npmjs.org/package/q, that's my choice. But I am not 
using any of the advanced features.

As for polyfil stuff, I don't really care about that. I do not plan to go 
back and revisit all my projects to replace q with vanilla stuff, unless 
specifically asked.

But ymmv.

On Saturday, January 25, 2014 12:44:18 AM UTC+1, Ian L. wrote:
>
> I'd like to use more promises in our codebase, but I'm not sure which 
> library on which we should standardize.
>
> Promises/A+ is the spec that's coming in ECMAScript 6, so I'd like to use 
> a library that's mostly a polyfill for whatever's going to be the standard 
> eventually. Which module is the closest? Or should I use a more mature or 
> full-featured library like Q knowing that the concepts are basically the 
> same and I won't have a terrible experience if in the future I need to port 
> code to the new standard?
>

-- 
-- 
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 nodejs@googlegroups.com
To unsubscribe from this group, send email to
nodejs+unsubscr...@googlegroups.com
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 nodejs+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: [nodejs] New module xpkg

2014-02-07 Thread zladuric


On Tuesday, February 4, 2014 2:43:25 PM UTC+1, Alex Kocharin wrote:
>
>  
> 04.02.2014, 17:01, "Oleg Slobodskoi" 
> >:
>
> Am 04.02.2014 um 13:46 schrieb Alex Kocharin 
> >:
>
>  1. Why JSON? This format was created for data serialization, and isn't 
> suited for maintaining by humans. 
>
> We could support cjson (https://github.com/kof/node-cjson) or yml ... but 
> I am not sure that json is an issue here. I personally had never a need to 
> use something more expressive in this case, but I am open for it. 
>
> YAML of course. It's the most sensible general purpose format used for 
> config files (unless your tool is able to change that config on the fly in 
> which case the issue starts to be complicated).
>


Out of curiosity, where can one get informed on these things?

Personally, I prefer json over yml. That way I never leave JavaScript way 
of thinking and encapsulating things. But I don't do all that much 
configuration, it's generally customizing pregenerated config files. I 
rarely produce packages, I mostly consume them.

-- 
-- 
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 nodejs@googlegroups.com
To unsubscribe from this group, send email to
nodejs+unsubscr...@googlegroups.com
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 nodejs+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


[nodejs] Re: Print form node

2014-02-07 Thread zladuric
That module looks like it is made node into a print server.

What exactly do you mean, print from the frontend? Click on the 'print' 
button? Where does this action print: to your printer attached to the 
node's server? Or to the users' printer?

Because if it's the former, it's in the modules' examples and readme page. 
I'd use this module to discover printers on wakeup. Then once I get a 
request from 'frontend' to do some printing, use this module to send it a 
print job.


If it's the later, then node is of no help, I think - unless you're doing 
something like node-webkit, which is a client side app.



On Wednesday, February 5, 2014 7:57:15 PM UTC+1, Lincoln de Sousa Cunha 
Lemos wrote:
>
> How i can print automatically with node from front-end?
>
> I found a module (Ipp - internet print protocol ).
> This help me start a communication with the printer, but i can not do with 
> this from front-end.
>
> Someone have any idea?
>
> -- 
> Lincoln Lemos
>
> *62 81998667*
>  

-- 
-- 
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 nodejs@googlegroups.com
To unsubscribe from this group, send email to
nodejs+unsubscr...@googlegroups.com
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 nodejs+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: [nodejs] How to download the same file in the same time?

2014-02-07 Thread zladuric
Is it all in the same window? Perhaps it is your frontend code that you 
need to take a look at?

On Monday, February 3, 2014 6:49:25 AM UTC+1, Rodrive wrote:
>
> I dont know why but actually i have this issue only with chrome. With 
> firefox or with "wget http://localhost:/test"; it works fine...
> So i have a new issue but it's only with chrome
>
> Le lundi 3 février 2014 03:42:20 UTC+1, Rodrive a écrit :
>>
>> I really dont get it. If i make something very simple the behavior is 
>> still the same : if i try to request 2 times to localhost:/test, the 
>> first time the download will start, the second time the download will only 
>> when the first download end.
>>
>> This is the small code i just run :
>>
>>> var express = require('express');
>>>
>>> var app = express();
>>>
>>>
 app.get('/test', function(req, res){
>>>
>>> res.download('./public/test.mkv');
>>>
>>> });
>>>
>>>
 app.listen();
>>>
>>> console.log('Listening on port ');
>>>
>>>
>> Le dimanche 2 février 2014 23:19:34 UTC+1, Rodrive a écrit :
>>>
>>> I'm totally agree with you but i dont know where the sync function come 
>>> from.
>>>
>>> I try to make this works ;
>>>
 var express = require('express');
>
> var app = express();
>
> var Throttle = require('throttle');
>
> var path = require('path');
>
> var filesize = require('filesize');
>
> var fs = require('fs');
>
>
>> // create a "Throttle" instance that reads at 100 kb/s
>
> var rate = +process.argv[2] || 100;
>
> var kb = 1024;
>
> var throttle = new Throttle(rate * kb);
>
>
>> app.get('/test', function(request, response){
>
> var filepath = './public/test.mkv';
>
> var file = {
>
> path: filepath,
>
> name: path.basename(filepath)
>
> };
>
>
>> fs.stat(filepath, function(err, stats){
>
> console.log('reading');
>
> response.writeHead(200,{
>
> 'Content-Type': 'application/octet-stream',
>
> 'Content-Length': stats.size,
>
> 'Content-Disposition': "attachment;filename="+file.name
>
> });
>
>
>> fs.createReadStream(filepath).pipe(throttle).pipe(response);
>
> //fs.createReadStream(filepath).pipe(response);
>
> });
>
> //console.log('file :' + file.name, 'size :' + 
>> filesize(file.size));
>
>
>> throttle.on('end', function(){
>
> console.log('Download over');
>
> response.end();
>
> });
>
> request.on('close', function(){
>
> console.log('Download cancel');
>
> response.end();
>
> });
>
> });
>
>
>> app.listen();
>
> console.log('Listening on port ');
>
>
> But even with just a basic use of express without the throttle, the 
 result is still the same.

>>> Thx for your help 
>>>
>>> Le dimanche 2 février 2014 22:12:11 UTC+1, ryandesign a écrit :


 On Feb 2, 2014, at 08:52, Rodrive  wrote: 

 > I am stuck with the download process. 
 > For example if i make a link to a file, when i click on the link the 
 download start. However i cant download the same file in the same time. 
 > If i click again the download will start only when the first download 
 will be finish. It seems that the url is "locked". 
 > 
 > How can I have the standard behavior : download the same file 
 multiple times in "parallel”? 

 If the server that’s serving these files is written in node, then 
 please show the code you’re using to respond to the request. I’m guessing 
 you’re using sync functions when you should be using async functions so as 
 not to block the main event loop. 




-- 
-- 
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 nodejs@googlegroups.com
To unsubscribe from this group, send email to
nodejs+unsubscr...@googlegroups.com
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 nodejs+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


[nodejs] Re: A really silly-novice question about events

2014-02-07 Thread zladuric
The keyword here is 'on' method. *source.on* vs *sink.on*. On is 
eventemitter method that listens to events emited on THAT object.

So if you emit stuff from source, attaching a listener to sink does not 
help. It doesn't matter what kind of object your sink is - it did not emit 
any radiation.

To make one object emit events and have others listen, you have two simple 
routes. One is to get attached to *source* from all your listeners, or the 
other is to use some kind of a bus or pubsub.

For the first version, your source would be an EventEmitter and it would 
emit('radiation'). And your sink can be any other object (including an 
event emiter), which has a listener.

Something like this:
var Sink =  new (require("events").EventEmitter)() /* or whatever else */
Sink.radiationHandler = function(){
console.log('run to the hills!');
}
var sink = new Sink;

Then you attach that method as a listener to it, like this:

source.on('radiation', sink.radiationHandler);

The other method I've described is a pubsub, kind of like this:

https://gist.github.com/fatihacet/1290216


On Thursday, February 6, 2014 12:45:47 AM UTC+1, q2dg2b wrote:
>
> Hello friends
>
> I don't know why this code doesn't work:
>
> var source = new (require("events").EventEmitter)()
> var sink = new (require("events").EventEmitter)()
> setInterval(function() {source.emit("radiation")}, 1000)
> sink.on("radiation", function(){console.log("¡Detected!")})
>
> However, this code does work:
>
> var source = new (require("events").EventEmitter)()
> setInterval(function() {source.emit("radiation")}, 1000)
> source.on("radiation", function(){console.log("¡Detected!")})
>
> Isn't possible to emit an event by an object and to receive this event by 
> another object, then?
>
> Thanks!!
>

-- 
-- 
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 nodejs@googlegroups.com
To unsubscribe from this group, send email to
nodejs+unsubscr...@googlegroups.com
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 nodejs+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.