[nodejs] Re: I am trying to connect with mongodb database but it throws some kind of error I am unable to understand

2020-07-27 Thread Zlatko
Hi there,


On Sunday, July 26, 2020 at 2:09:29 AM UTC+2, Aman Kr Sharma wrote:
>
>
>
> (node:94165) DeprecationWarning: current Server Discovery and Monitoring 
> engine is deprecated, and will be removed in a future version. To use the 
> new Server Discover and Monitoring engine, pass option { 
> useUnifiedTopology: true } to the MongoClient constructor.
> (Use `node --trace-deprecation ...` to show where the warning was created)
> MongoNetworkError: failed to connect to server [
> cluster0-shard-00-00.lpcoo.mongodb.net:27017] on first connect 
> [MongoNetworkError: connection 5 to 
> cluster0-shard-00-00.lpcoo.mongodb.net:27017 closed
>
>
What is your exact connection string? If you just pass 
"cluster0-shard-00-00.lpcoo.mongodb.net:27017", try adding `mongodb://` 
before it. But MongoNetworkError seems to indicate that your _server_ is 
either down or unreachable. Can you reach it from another MongoDB client? 
Is the error only in 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 view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/90f783fa-e18a-4cd0-86bc-7f0dd8b8d0b8o%40googlegroups.com.


[nodejs] Re: Failed: Trying to use handlebars in NodeJs using Expressjs

2020-07-22 Thread Zlatko
Hello,

It looks like a user issue, but there's not enough details to be certain.

On Tuesday, July 14, 2020 at 3:14:15 AM UTC+2, Aman Kr Sharma wrote:
>
>
> Error: ENOENT: no such file or directory, open 
> '/home/aman/Documents/Coding/nodejs/expressjs2/views/layouts/main.handlebars'```
>   
> This is what I am doing ```app.engine("hbs", expressHbs());
>
>
Does this file exist? Can you show the one including  this 
"main.handlebars" as well?

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 view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/7ceac5b3-9b65-4630-9393-5c987c8f8001o%40googlegroups.com.


[nodejs] In a node (express) route using mongoose, which of these 2 methods is superior to ensure that an object is added to a collection?

2019-01-24 Thread Zlatko
Hello Sivi,

Your problem was likely not related to the unshift method at all. That method 
is synchronous, there is no race. Something else must have caused the issue: 
front-end bug, missing content type header, the database was down or your API 
server crashed, cross domain request, but not this. In that respect, there's no 
difference between the two methods.

On the other hand, I find the second approach better, because while 
functionally equivalent, it's easier to understand what's going on at a glance.

There are a few things you could do to improve it, though.

For one, that error handler at the end. You should really add a different 
status code. And for typical clients, you would also want to send this as JSON 
payload, not raw string - it would be easier to handle the error. Furthermore, 
this way you might be exposing unneeded details about your server to the 
clients, while at the same time, _,not_ providing useful info. E.g if I was 
building a client that used this API, I wouldn't know if the error is mine 
(e.g. Missing field or some validation), yours (e.g. Server had disk full and 
can't work any more), or database error (e.g. unique constraint on an index was 
violated).
Another point would be that you're making an unneeded call to the database 
(this is MongoDB, right?). You could do the whole transaction in one go, find 
and update with a single query (since you don't seem to be checking for e.g. 
Duplicated entries anyway).
The third thing would be that you could create a light service layer and take 
all these database shenanigans out of your endpoint route. The router would get 
the id parameter from the url and the title and content from the body, and pass 
it on to a service that hid all this stuff. It adds the overhead of an extra 
file, but brings in a much easier to maintain code, reusability etc.


Hope that helps.
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/300f1cda-e966-4ca5-8e92-e1fe95cd1971%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Re: Leaving NodeJS after years of learning and writting projects - Back to PHP

2018-12-28 Thread Zlatko
Hi Leandro,

Thanks for posting. I believe this is a valuable feedback - and to a point, 
possibly a valid concern that you're describing.

Small agencies and one-man teams have used the internet by providing the 
code which the client then hosts on a shared service and it's online, no 
matter where you pick it. The venerous LAMP stack was the go-to solution 
and still drives a huge part of the web. It would not be unreasonable to 
look for similar with a new platform, praised to be the new killer-app, 
allegedly so much better than PHP - but you can't even deploy it on a 
shared hosting service.

However, I'd like to point out a few things that you may have missed, or 
haven't thought about. Or if you have, but have different conclusions than 
I do - please point them out as I'd like to know if I have flaws in my 
logic.

Anyway, let's assume a few different aspects.

Aspect one - costs. You say that you have a major problem with cost prices, 
with cheap node being 10x more expensive than PHP. 

I'd say that on average, cheap shared hosts offer something in the range of 
1$ (give or take) for a shared host ,shared database or few, up to 10-100 
MB or similar. The cheapest you can get away with for a Node app is free. 
If your app is stateless, if your traffic is so low that a cheap 1$ shared 
PHP host is good enough for you, you can likely fit all your requests in 
the free alotments of the more popular serverless/cloud providers. Even the 
database providers, e.g. MongoDB which is what MySQL would be in a LAMP 
stack, you have free offerings until a certain size - usually more than 
accomodating enough for low traffic websites.

So I think it's a wrong assumption - hosting a node app can be affordable 
without "expensive" VPS services.

But let's say your app is a bit more demanding, and you really need a VPS 
service. The cheapest *reliable* VPS providers that I know of, Scaleway and 
Hetzner, provide good and stable VPS nodes for a Node app for less then 
2.5$ a month (2€). DigitalOcean, as a much more "famous" solution, or 
Linode or similar, cost 5$. Which is really, really affordable and 
reliable. Such a VPS can hold both a node app and a good database server, 
such as MySQL, without issues. If you want redundancy, you could have two 
and have replicated server.

So, a VPS service itself is not that expensive.

But the biggest problem here is the domain. What do you use PHP for, what 
do you use a Node app for? PHP is usually just a CMS, with maybe a contacts 
form or a comment box or similar. As soon as it gets used more seriously, 
you can't rely on shared hosting, and you have to go VPS route anyway.

And Node, while it can also do that - in which case a serverless version is 
more than enough and will go a long long way before you need to start 
actually paying for some small monthly fee.

So how do you use Node? What kind of projects you need to host? What are 
your strategies for it? What are your hosting strategies for PHP for the 
same projects?

If you wanna make a comparison, you'd need to compare much more about how 
you approach your work.

Otherwise, it really is back to the nineties, with all the nineties horror 
stories with it.

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/9a146860-4987-4595-973d-231e65497a2d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Re: Why the email is not sending

2018-12-07 Thread Zlatko
Maybe your email got caught in Google's Spam filters. Or one of your email 
rules deleted it. Maybe obvious, but did you check the spam/trash and such 
folders?

Also, maybe your actual sender and/or domain combo is weird. E.g. you can 
set up a domain DNS so that it's only allowed to send emails from a certain 
IP address or range, or such combinations.

Did you check here?

https://support.google.com/mail/troubleshooter/2920052?visit_id=636797743968862672-3109617686=en=2

Zlatko

On Thursday, December 6, 2018 at 5:21:56 PM UTC+1, Ryan Liu wrote:
>
> I was trying to send a mail through my own smtp server made using 
> smtp-server <https://nodemailer.com/extras/smtp-server/> and I checked my 
> Gmail account and it is not sending.
> Here is my smtp server.
>
> const SMTPServer = require("smtp-server").SMTPServer
> var fs = require("fs")
> const server = new SMTPServer({
> secure: true,
> key: fs.readFileSync("C:/Users/Jerome/smtp.key"),
> cert: fs.readFileSync("C:/Users/Jerome/smtp.cer"),
> size:1024,
> onAuth(auth, session, callback){
> if(auth.username !== 'abc' || auth.password !== 'def'){
> return callback(new Error("Invalid Credentials"));
> }
> callback(null, {user: 123}); // where 123 is the user id or 
> similar property
> },
> onMailFrom(address, session, callback){
> if(address.address !== "nor...@example.com "){
> return callback(new Error("Only nor...@example.com 
>  is allowed to send emails"))
> }
> return callback()
> },
> onData(stream, session, callback){
> stream.pipe(process.stdout)
> stream.on('end', () => {
> if (stream.sizeExceeded){
> return callback(new Error('size excedded'))
> }
> return callback(null, "sent")
> })
> }
> });
> server.listen(465)
> server.on('error', function(err){
> console.log(err)
> })
>
>
> Here is the mailing program
>
> const nodemailer = require("nodemailer")
> const transport = nodemailer.createTransport({
> host:"localhost",
> port:465,
> secure:true,
> auth: {
> type:"login",
> user:"abc",
> pass:"def"
> },
> tls: {
> rejectUnauthorized: false
> }
> })
> transport.sendMail({
> from:"nor...@example.com ",
> to:"xx...@gmail.com ",
> subject:"test",
> text:"test"
> }, function(err,info){
> if (err) {
> console.log(err)
> } else {
> console.log(info.response)
> }
> })
>
> I ram the smtp server first then the mailing program and the smtp server 
> responds with a 250 sent
> What is wrong with the code or what happened?
> How should I change the code?
>
>

-- 
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/5f6340db-4be6-4e11-83ae-4cc9b38ac723%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] publish node js with mongoDb in windows server

2018-10-16 Thread Zlatko
Hello,

I haven't seen Plesk in years, but googling got me to this page which says you 
need to install MongoDB in a Docker container:
https://support.plesk.com/hc/en-us/articles/115004540294-How-to-install-MongoDB-database-server-in-Plesk-

Have you tried that?

-- 
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/77aec664-2289-435f-825e-6490bedae17a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Unexpected token _ at Object.parse (native)

2018-10-08 Thread Zlatko
Hello,

In addition to what the others suggested, I'll suggest removing the outer, 
double quotes around your thing and it's going to be an object instantly, no 
de-serialization needed. That depends on your use case, though, but in the 
example you provided, it will work's
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/5e542dc4-afcc-4c49-8866-a214c825a070%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Custom class object as Key in a Map

2018-09-29 Thread Zlatko
Yes, in pretty much the same way: 
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map

There's more on that link, like Setc and WeakMap, so check them out, see what 
works best for your use case.

-- 
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/56d1fbde-8099-4afc-9f54-dd72fd55c61c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Passport how to authentication between services ?

2018-09-29 Thread Zlatko
Well, as you've said yourself, your first project uses passport-mongodb or 
similar authentication strategy. What does your second project use? Are you 
accessing it exclusively server-to-server or also regular fashion, from a 
client? If it's server to server, do you need to also pass along authorization 
info (oh behalf of which user is the first server asking for resources on the 
second)?

In general, you can use some relatively simple way, like encrypt the 
communication with a preshared key or similar. But in most cases, you should 
try to implement something like OAuth.

With OAuth, you have ensured all of these scenarios - server-to-server, 
client-to-server, server-to-server with clients authorization etc.

-- 
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/1c883541-c7ea-4688-a059-a15dd7502bce%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [nodejs] Re: javascript vision thing

2018-09-22 Thread Zlatko Đurić
Hi all,

I don't know why I can't resist this troll. I've just spent half an hour
writing an elaborate answer on how the whole premise is wrong, knowing that
this is a known troll account. Well, I've deleted it all and will not fall
for his trolling again.

 (Btw I thought this list is moderated, how come his same-all troll
ramblings always pass the mods?)

Zlatko

On Sat 22. Sep 2018 at 18:26, Michael J. Ryan  wrote:

> Considering how many js devs fail to answer "what values evaluate to false
> in JavaScript". It isn't the new features that are the problem.
>
> There's a combination of problems.  People believing they're better
> developers than they are.  People who look down on js and front end
> development.  And those ahead to learn new things.
>
> JS isn't really evolving any more than Java, C#, go, python and others as
> a whole in the past 20 years.  And having to fight uphill to use newer
> features is a pain.  I'm not on the younger side of this (I'm 42)... But
> I've managed to keep up.
>
> On Fri, Sep 21, 2018, 17:14 kai zhu  wrote:
>
>> a problem i've observed in industry is that many es6 language-features
>> have the unintended-consequence of incentivising incompetent
>> javascript-developers at the expense of competent-ones.  its generally
>> difficult for many employers (even those knowledgeable in general-purpose
>> programming), to discern between:
>>
>> a) a competent javascript employee/contractor who can get things done and
>> ship products (albeit with legitimate delays), and
>> b) an incompetent-one who can easily hide themselves in non-productive
>> es6 busywork, and continually pushback product-integration (again with
>> “legitimate” delays, until its too late).
>>
>> its gotten bad enough that many industry-employers no longer trust
>> general-purpose-programming technical-interviews when recruiting js-devs,
>> and rely almost exclusively on either a) an applicant's reputation /
>> word-of-mouth for getting things done, or b) their ability to complete a
>> time-consuming tech-challenge, where they must demonstrate ability to ship
>> a mini-product.  both methods are not scalable to meet the demand in
>> industry for qualified js-devs in product-development.
>>
>> the only solution i can think of to this industry-problem is to hold-back
>> on introducing new disruptive/unproven javascript design-patterns, and
>> figuring out how to educate the industry with tightened javascript
>> style-guides and existing design-patterns proven to work (more is less);
>> generally, ways to enhance the current, woefully inadequate “bullsh*t
>> detector” of employers so they can better identify and
>> mentor/train/weed-out unqualified js-devs.
>>
>> kai zhu
>> kaizhu...@gmail.com
>>
>> ___
>> es-discuss mailing list
>> es-disc...@mozilla.org
>> https://mail.mozilla.org/listinfo/es-discuss
>>
> --
> 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 a topic in the
> Google Groups "nodejs" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/nodejs/p81p-_FqS-s/unsubscribe.
> To unsubscribe from this group and all its topics, 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/CA%2BpgmMoRmv-P-8a%2B6JCj8szBcJ_32fPULL3DqrZp%2B3SgMZLTDw%40mail.gmail.com
> <https://groups.google.com/d/msgid/nodejs/CA%2BpgmMoRmv-P-8a%2B6JCj8szBcJ_32fPULL3DqrZp%2B3SgMZLTDw%40mail.gmail.com?utm_medium=email_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
-- 
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/CADu3pbxhg6P%3DKqJRKPzpGipeNQi92f9vvm3f4g%2BgnM5m1NHHUw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [nodejs] Re: right way to use nodemailer and nodemailer-smtp-pool

2018-08-15 Thread Zlatko Đurić
Well some config issue is obvious: 1. either your client has too many open
connections, or it sends too many messages on a single open connection, *or*
it sends too many messages in a given time frame (some systems also limit #
of messages in a time unit).
Maybe your app is using a cluster module so you open too many connections
from the server, even though you think you limited to X?

So I'd suggest this:
1. instead of sending your messages from your app's other modules, have
them stored on a message queue. Can be a database, like Redis, SQL,
whatever, or it can be something like RabbitMQ - whatever you already use.
Just put them away.
2. Have another subsystem in your app that periodically checks if there are
messages on this queue to be sent.

This would be my approach regardless of the limits. That's how you decouple
your app and the sending of messages. You can deal with multiple app
servers, with recovering from crashes, many things. You can even deploy the
whole messaging subsystem (sending mails) as a separate node app.

Now with the message sending sitting on it's own somewhere, you can do all
this fun stuff about rate-limiting your message throughput. You can limit
your system to do, e.g. max 1 mail per 5 seconds, or per 1 minute or
similar. And to be certain, go to the mail server admins and ask them about
the limits, then go bellow those limits.



On Thu, Aug 9, 2018 at 3:11 AM sunshine o  wrote:

> I have restriction from my company environment to use any other SMTP
> server which is why I think I can send 5, not more one time.
>
> I tried playing with maxConnections etc properties increasing values but
> did not help.
>
> So now, my approach is to live with number 5. But making it send multiple
> times. I split the emails data into batches of 5 and then send and
> delay/wait. Still first batch of 5 gets delivered,
> at next i get error.
>
> "Too many messages"
> "Too many sessions".
>
> So that means here problem is with my connection close etc. So when next
> batch starts, it should be new connection.  So I try to initiate the
> connection (createTransport())  with each batch.
> Please let me know if i am completely wrong approach.
>
>
> On Tuesday, August 7, 2018 at 12:35:22 PM UTC-4, sunshine o wrote:
>>
>> I have case where I send multiple emails( with different contents and
>> subjects), all in array , traversed in a loop to  deliver multiple
>> receipients.
>>
>> First I used simple nodemailer and i found more than 5 emails in a row, i
>> get errors.
>>
>> I have input data in a json form where I calculate how many emails and
>> what contents will go. So senders list and contents are not static and
>> calculated in same code before sending out emails.
>>
>> so first case,
>> 1. Use simple nodemailer. Mail sending part is a promise. Works but not
>> more than 5. Each email 's return messages etc can be tracked fine and
>> final results can be returned since emails work sequential.
>>
>> 2. Use nodemailer-smtp-pool to increase number of emails.
>> Strange that emails do not work normal. 1 or 2 emails are sent and 3rd
>> not. Then if I trigger email code multiple times, within seconds it works
>> once or twice with error messages.
>> "Mail Command Failed: 421 #4.x.2. too many messages for this session"
>>
>> Code is:
>>
>> var smtpPool = require('nodemailer-smtp-pool')
>> pooledTr =nodemailer.createTransport( smtpPool{ host: "", secure:false,
>> port: 25, maxConnections:25, maxMessaes:50, rateLimit:10...})
>>
>> then in a loop for all the emails,
>> pooledTr.sendMail(mOptions , (err, callback)=>{})
>>
>> Now, we do not have promise anymore, as we do not want to wait till first
>> email send and returns.
>>
>> Can any one help if I need to use events in pooledtransported, like wait
>> till connection is idle to send. Also If I need to add time wait or promise
>> till it delivers?
>>
>> I googled but do not what examples per my scenario.
>>
> --
> 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 a topic in the
> Google Groups "nodejs" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/nodejs/fc1xYKNdxFk/unsubscribe.
> To unsubscribe from this group and all its topics, 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
>

[nodejs] Re: right way to use nodemailer and nodemailer-smtp-pool

2018-08-08 Thread Zlatko
What errors do you get in the "simple nodemailer" case? The same one?

I seriously suspect your problem is in maxConnections and maxMessages. 
Reduce that to some small value like 5 each, or even less. From my sysadmin 
days, I remember some bigger, known domains even had these set to 1, so 
this is also per-domain configurable. These are the reasons services like 
mailgun do well - they gather a lot of specific knowledge about individual 
domains.

Zlatko


On Tuesday, August 7, 2018 at 6:35:22 PM UTC+2, sunshine o wrote:
>
> "Mail Command Failed: 421 #4.x.2. too many messages for this session"
> var smtpPool = require('nodemailer-smtp-pool')
>
 

> pooledTr =nodemailer.createTransport( smtpPool{ host: "", secure:false, 
> port: 25, maxConnections:25, maxMessaes:50, rateLimit:10...}).
>

-- 
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/1168f3e0-c4f2-4659-a698-d10f83936af9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Re: Check if internet connection is working behind a proxy

2018-05-02 Thread Zlatko
>From client's perspective, navigator check doesn't care nor sees proxies. It 
>tries to do a connection and that's it.

Alternatively look at what you've got.
Internet-available makes a dns query, but your proxy/firewall does not allow 
direct communication. But a simple http fetch should work, if your app uses 
default system proxy configuration (in vast majority of the cases). So I would 
guess that a combo of no-direct-dns (or anything outgoing, for that matter), 
but normal connection from the client-side script which uses something like 
automatic (OS-controlled) proxy config should tell you it is a proxy.

-- 
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/a61f88b7-8308-43f7-9590-cd82adb2008d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Re: Node.js Long running Task scenario

2018-03-13 Thread Zlatko
Hi MrNode,

This is way too generic task description to be node-specific. We don't know 
how is the file processed. We don't know how is this CSV processing needs 
to be atomic or not - it seems yes, but not clear. We don't know if you can 
abort it or not. We don't know if you want to block the upload function 
completely or you merely block it because you can't abort the previous job. 
Such a thing needs to be designed with the task specifics in mind.

Here are a few scenarios, depending on your requirements.

Under assumption that the 100,000 rows in the CSV are individual "work 
items", and the whole CSV of them is a "batch of work", you  can, on 
upload, simply create a queue of 100,000 things to process. Also, hold a 
hashmap of these work items, so you can address them by the batch. Also 
have a work dispatch protocol and a node Microservice that takes the rows 
to processing, one by one, and take them off this batch queue into another 
queue, "pending batch finish". Once it is all completed, mark those 
"pending finish" as "completely completed" and clear the batch. Expose a 
"Cancel batch work" functionality to user, if they click "cancel current 
batch", you clean up all the pending tasks so that your worker microservice 
stops processing these. Also, mark the batch as canceled, so you can clean 
up the work items that were already completed.

If you can't break processing into items (maybe you're aggregating things 
over those 100,000 rows), perhaps you can run this aggregation in an 
interruptible loop. Then your "Cancel batch work" would first check if 
there are running aggregations and interrupt/abort them, then proceed as 
planned and run the new file.

Your least flexible option, e.g. you cannot stop the processing once it has 
started, is to at least provide upload queue - the first file uploaded is 
getting processed, and now you expose an endpoint where you can upload 
additional CSVs. They are just sent to server and are waiting. You can 
still cancel those "pending" CSVs and upload new ones instead, even if ytou 
can't break the main, running CSV. Then expose a simple "status" endpoint 
where you can indicate your status to the user, e.g. "processed 40,000 of 
100,000 rows, 3 CSVs pending processing".

You would have to keep all those locks and things outside the running 
process - Redis is probably the simplest to use - because you might be 
running these tasks (upload, processing, statuses) on different servers, or 
at the very least, different workers in your Node cluster instance.

But these are very rough guesses. With a lot more details, I could provide 
a better overview. Shoot if you have other questions.



-- 
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/a4cb47fd-bec1-41b8-bc28-1d525d457d20%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Re: Remove BOM from Google supported devices csv

2018-03-12 Thread Zlatko
Not sure if it helps, but here's what worked for me on a recent project:

payload = payload.replace('\ufeff', '').replace(/rn/g, '')
.replace(/\\"/g, '"');

Hope it helps?

-- 
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/4e320f7c-9372-4df0-94bc-4cdfb7d48e53%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Re: Taking Node-report of already running process

2018-03-08 Thread Zlatko
Well, did you look at the docs ? 
"can also be triggered by sending a USR2 signal to a Node.js process"

So, `kill -USR2 ` should do the trick.


Btw, their docs say you can do this:

var nodereport = require('node-report');nodereport.triggerReport();

So if all else fails, build yourself this into a function, and shoot this on 
interval, or maybe on an external trigger (e.g. protected API endpoint if this 
is a web app).



On Wednesday, March 7, 2018 at 7:39:32 AM UTC+1, Kumar Nikhil wrote:
>
> Hello ,
>
>  As of now *"node -r node-report application.js"* creates a new process 
> and takes the report of the new process. 
> But I want to take the node-report of the existing running process.  
>
> Is there any way to do that ?
>

-- 
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/2e3f71b1-1921-4bd1-898c-e74ea9653b25%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Re: Are functions which defined using eval or new Function() optimized?

2018-03-03 Thread Zlatko

Hi Koray,

Apparently, the answer to your original question is "yes", functions 
generated by "eval" or "new Function()" will get optimized. I've asked one 
of the V8 developers on Twitter, he even referred on how Webpack (pretty 
popular and well known JavaScript package) achieves crazy improvements on 
their latest iteration:

https://mobile.twitter.com/bmeurer/status/969599687274745856


-- 
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/d7e7e0a7-f604-425d-a689-2f6cc2e44ec5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Re: Are functions which defined using eval or new Function() optimized?

2018-03-02 Thread Zlatko
Hi,

Good question! V8 Googlers say nothing eval does is optimized and almost 
absolutely must be avoided (and they same for Function constructor IIRC) - 
but what about the product of it?  I don't know, maybe you can run a few 
tests with v8-debug. I would be interested in results if you do run such a 
test.

But I have another question: why would you deploy new code this way? Can't 
you have some continuous deployment, partial rollouts etc this way? Or send 
all requests for unknown functionality to a pubsub, and then attach your 
new code there to respond?

-- 
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/bbbd3192-1a76-4221-8be5-652794b3d693%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Re: how to Auto-generate models in nodejs

2018-03-01 Thread Zlatko
As an alternative to ejs, you might be able to use something like Swagger 
and one of it's plugins.

-- 
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/52fad3ca-b236-476e-a92f-f47d96ec48cc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Re: Allowing access to an endpoint under a condition?

2018-02-01 Thread Zlatko
Like Warner has said, take a database. Something like redis, in this case. 
Or even a free hosted offering, if it is not mission critical. Or get a 
firebase client. In any case, some external persistent way of storing and 
retreiving this.

As an aside, it would probably be better to make checking and manipulating 
this a middleware. Extract your actual "business logic" to a separate file, 
and put your MY_TOGGLE check in a middleware. It enables you to easier 
test, or e.g. later change the mechanism, or where you store the toggle or 
similar.

Something like this:

const app = express();
const { getToggleState, flipToggleState } from './toggle-manager';
app.use('/requests', async function (req, res, next) {
 const isToggleOn = await getToggleState();
 if (isToggleOn) {
next();
} else {
res.status(403).end('Forbidden');
}
});

app.use('/requests', yourRegularHandler);

app.post('/stop', (req, res) => {
flipToggleState();
res.end('Ok');
});

-- 
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/fc55e8b8-6992-430e-99f6-eb9f5e8b6f12%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Re: Performance implications if next is not called in the middleware?

2017-12-28 Thread Zlatko


On Wednesday, December 27, 2017 at 8:18:51 AM UTC+1, node...@gmail.com 
wrote:
>
> In the middleware function, to move on to the succeeding middleware 
> function, we need to invoke the next function. As we all know, if we omit 
> the call the next() function, the request will be hanging. In these 
> scenarios, are there any performance implications due to this? If yes, then 
> what are those issues? What might be the issues if we do not explicitly 
> call next function and requests are left hanging?
>
>
>
This depends on the clients, settings, etc. If the clients close the 
requests or timeout, and if there aren't that many of them, you might do 
fine. After a client disconnects, express will clean up and close your 
request (usually). The thing is though, until the connection closes, this 
request is left hanging. And with it all other request-allocated resources, 
such as session info etc. So if enough of the requests pile up, you might 
run out of memory or other resources. You also might have some resources 
open, locked, or whatever, and you require next middleware or error 
middleware or someone else to clean this up. E.g. depending of what libs 
you use, you might end up with one that is lousy and opens one db 
connection per request, and you run out of pool of db connections, so all 
other ops are left waiting for timeouts and requests closed etc.

So it can get to performance or even more, stability issues. It's usually 
not a super smart thing to leave middleware hanging.


-- 
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/906decc1-84bb-428a-b501-27b2fae88b98%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Re: How best to deploy NodeJS commandline application

2017-11-30 Thread Zlatko
Hi Michael,

node-deb is one way to distribute that package. But since your users will 
have to have a node binary on the system anyway, you can still use npm, 
just publish the app in a private namespace. Name your package with the org 
scope, e.g. my private packages on npm are scoped to *@zladuric*, e.g. 
"name": "@zladuric/my-project". When you have your company organization (or 
personal account), you can publish like that and only give access to people 
(or orgs) which you want to.

It's definitely a viable alternative.

-- 
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/7e9b2a07-095d-42ef-8df8-abddb17b896a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Re: New to node.js. Need help with Node application running through Apache web server

2017-11-14 Thread Zlatko
Hi,

On Friday, November 10, 2017 at 12:07:56 AM UTC+1, Kyle Hall wrote:
>
>
> In order to view the application off our VPN, we set up an Apache proxy to 
> our public-facing test URL: http://www.testdomain.com/calendar. The 
> application runs, but none of our CSS or JS files show up. They are all 
> 404ing in the debugging console, showing up as 
> http://www.testdomain.com/css/layout.css instead of 
> http://www.testdomain.com/calendar/css/layout.css.
>
> We've found that if we add /calendar to the CSS and JS paths in the 
> layout.jade file, it works. But we're wondering if there is a way to set up 
> our Apache proxy so that it only proxies the front-end pages and not the 
> internal CSS and JS folders. The other problem is that we also have JS 
> files at the root of our application, so we would likely have to proxy 
> ignore those files individually as well.
>
 
Well, there are a few things. One, you would be much better off if you 
serve the assets directly by apache. Say your static stuff is in your 
*/var/app/public/assets/{css/img/js}* directory - you would tell your proxy 
(in this case apache) to serve any of the */calendar/assets/** requests 
directly from there. That way you offload serving static files from your 
app server (Node).

The other thing is to setup static route differently - e.g. you probably 
have somewhere in your code a line like this: *app.use('/assets', 
express.static(__dirname + '/public/assets'));* Now, what you do there is 
say *app.use('/calendar/assets', express.static(...));*. The first solution 
is much better because your node app will always work on */ *path if served 
standalone (like when you're working on the app), and your proxy can pick 
and choose on which virtual directory you serve from (e.g. if you want to 
change /calendar to /cal, or even serve from both, your app developers 
don't need to know about this at all, the ops guy sets it up as he wants 
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/923634b1-c60a-4b4d-9ae0-db40208bbcc8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Re: Synchronous for loop

2017-10-25 Thread Zlatko


On Wednesday, October 25, 2017 at 7:38:37 AM UTC+2, gupta@gmail.com 
wrote:
>
> Here is my code. Its a simple one
>  for(var a=0; a var dId = dResponse[a].dId;
> console.log('dId-->' +dResponse);
>   var dUrl = url?id=' + dId;
>   console.log('Url:'+dUrl);
> }
> Every time it returns the same url.
>
>>
>>

You didn't show the whole code - what's in dResponse array? But, your title 
says "Synchronous for loop", depending on your node version, here's a 
simple example:

const request = require('request');

function callRemoteApi(url) {
  return new Promise((resolve, reject) => {
console.log('Fetching', url);
request(url, (err, res) => {
  if (err) {
return reject(err);
  }
  console.log('Got', url);
  const result = JSON.parse(res.body).url;
  resolve(result);
});
  });
}
async function runTest() {
  const urls = [
'https://httpbin.org/delay/5',
'https://httpbin.org/delay/1',
'https://httpbin.org/delay/3',
  ];
  console.log('Urls ready.');
  let promises = [];
  for (let url of urls) {
promises.push(callRemoteApi(url));
  };
  console.log('Promises ready.');
  await Promise.all(promises.map(async promise => console.log('Result of 
promise:' + await promise)))
.then(() => console.log('All done.'));
}

runTest();

Now, if you run this code, it'll show you how things are working.

So the for loop example is indicative of potential issues with sync for 
loops. It takes an url, *waits* for it to return, and then goes on to the 
next.
Now, the other example works much better: we execute all promises 
immediately, in parallel. And as they come back, we get the results logged 
immediately.

Not sure how applicable this is to your situation, but if you post more 
code, we might help out.



 

-- 
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/5f91c74d-12e6-499e-b7ad-6918048604dd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Re: help beginner with basic app

2017-09-25 Thread Zlatko
Hello Anton,

Did you try with nodeschool.io tutorials? Those are really great to get you 
started. Also, they start from the basics and are relatively up-to-date. 
Also, they teach you the core principles so even when modules change later, 
you can still figure out what's going on.
But that's very general stuff. If you want to do a simple express app, just 
go to Express.js Getting started pages: 
http://expressjs.com/en/starter/hello-world.html
And one more thing - learn Node (backend) and HTML (frontend) separately. 
First, learn how to make a simple server that does these two functions. 
When you do that, you have a "backend". Then go work on the "frontend", 
HTML pages or app. It'll make learning this stuff much easier.


On Monday, September 25, 2017 at 12:15:49 AM UTC+2, Anton Inocentiu wrote:
>
> hello everyone
> im trying for a while to write my first nodejs app
>
> my brain just cant understand 
> i tried tutorials, also got some books 
> beginning nodejs, the node beginner book
>
> cant get pass hello world, i just cant put it together, 
>
> i need something easy, prefferably 1 file, less modules, NO jquery
>
> a html with 2 buttons, that executes 2 functions on the server and sends 
> results or message back to the client page to display in a div (executed 
> function 1 or 2)
>
> will run it from a localhost,basically just a gui for other stuff
> i assume xhr would be enough for localhost
>
> last stuff i tried was this 
> http://siteolytics.com/node-js-a-simple-tutorial-with-example/
> after installing modules it said "Error: Route.post() requires callback 
> functions but got a [object Object]"
> these modules change too fast, thats why i want something basic whithout 
> too much modules to rely on
>
> is there a node forum besides ?
>
> please help
> 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+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/bee16986-bc19-453b-a55e-caca4169dda4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Re: What is the below express router doing

2017-09-07 Thread Zlatko
Hi,

On Wednesday, September 6, 2017 at 4:15:19 PM UTC+2, Rohan Pota wrote:
>
>
>  1. How does `Promise.all()` work ?
>

Promise.all 
works
 
like this: you give it *an array* of promises, and it returns a *single 
promise* that is resolved when all the initial promises are done.
Meaning, in a case like this:

Promise.all([p1, p2, p3, ..., pn])
  .then(handlerFuinction)
  .catch(errorHandlerFunction);

In the example above, you give a handler (callback), but it won't get 
called until ALL of the p1, p2, p3.. are resolved.
If *any* of the promises fails or throws, your entire chain will get 
canceled. Now be careful here, some of the promises may have been resolved 
already (e.g. updated stuff in db), while others are still in progress, so 
you might have to do some cleanup call in the .catch handler.

In your case, you first have a promise to be something of this:

req.payload ? User.findById(req.payload.id) : null,

So if a call to this endpoint was authenticated (I assume that's wath 
auth.optional does), we get a User.findById(), otherwise we just get *null* 
(without 
going to db).
So in any case, your first promise will either return a user object or it 
will return *null*.

Your second promise is that execPopulate() promise.

Now, *when both of these* are done (both getting the user and populating 
that article), your last handler gets called. But if any of those fails 
(e.g. the database is down or the network breaks or whatever)

 

>  2. Why do we need to repopulate author field in `router.get()` method 
> when already did that in the `router.param()` method?
>

Well, I can't tell easily without looking in the code, but it looks like 
you can take out the second call to populate. That'd be the second promise 
in your Promise.all array. You could also skip the router.param up there 
completely, but you may be using that somewhere later on the router, so 
make sure it all works without it if you go that route (no pun intended :)).

 

-- 
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/5173d1d1-f81e-4522-9fe7-d990f847e5de%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Re: Disconnecting frequently after updating Node.js v6.9.4

2017-07-31 Thread Zlatko
Few suggestions from me:

On Sunday, July 30, 2017 at 9:57:54 PM UTC+2, k yosimoto wrote:
>
>
>- Update versions
>   - node.js@6.1.0 → 6.9.4
>   - socket.io@1.4.6 → 1.7.2
>   - express@4.13.4 → 4.14.0
>   - body-parser@1.15.1 → 1.15.2
>   - jquery@2.2.3 → 3.1.1
>   - jsdom@9.0.0 → 9.9.1
>
>
What if you just update the Node version? Try that first. The try updating 
one thing at a time and see where the thing breaks. Because when you update 
one of these npm packages, they will likely pull in many others as well, 
and some of those others might be flattened out by the new npm so your 
_other_ modules will also have new versions of their dependencies without 
realising it.



>- State at disconnection
>   - 
>   
> The response time of the request (polling) before disconnection was 85 sec
> , and "400 Bad request" error was output in the next request. 
>
> (The response time in the normal state is 25 sec)
>
>  
>


You mean socket polling? Or what url specifically?

One more idea. The great thing about Node 6 is that you can easilly run a 
debugger and attach chrome dev tools to it and monitor the state. At the 
very least, get a few dumps and check what's different between the old and 
new versions.

 

-- 
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/dafaef88-52b3-403e-a637-b92538c2cb82%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Re: Hot reload plugin for node.js

2017-07-31 Thread Zlatko
Hi,

I really do not think this is production ready.

1. Simple async code.

Simple example:

// m1.js
const label = 'Hi world';
setInterval(() => console.log('From m1:', label), 1000);
exports.label = label;

// m2.js
const dload = require('../index');
const mo = dload.new();
mo.fs = require('fs');
mo.path = require('path');
mo.co = require('zco');
mo.m1 = require('./m1.js');
mo.co(function * (co_next) {
  let label = mo.m1.label;
  console.log('Old label:', label);
  setInterval(() => {
dload.reload(mo.path.join(__dirname, './m1.js'));
label = mo.m1.label;
console.log('New label:', label);
  }, 1200);
})();


Run m2, then change the label manually a few times and save. All sorts of 
stuff in there:

>From m1: Hello world
>From m1: Hi worlds
>From m1: Hi world
>From m1: Hello world
New label: Bye bye
>From m1: Hi worlds
>From m1: Hi world
>From m1: Hello world
>From m1: Hi world
>From m1: Hi world
>From m1: Hello worlds
>From m1: Hello world
>From m1: Hello world
>From m1: Hi world
>From m1: Hi world
>From m1: Hello world
>From m1: Hi world
>From m1: Hi worlds
>From m1: Hello world
>From m1: Hello world
>From m1: Hi worlds
>From m1: Hi world
>From m1: Hello world
>From m1: Bye bye

I know there's the _release handler, but what if my interval is not in my 
code, but in some library my original module required? I would be totally 
scared to run this in production and try reloading things when all kinds of 
resources are attached out there. E.g. I sometimes keep anything db-related 
in a separate repository. And that stuff touches say Redis, MongoDB and 
RabbitMQ. I know I will have to write manual _releasse code. But if I miss 
just one thing, it's not good. And if I let my colleagues use that? They 
don't even know what to release! OTOH if the server is killed, I _know_ 
everything is shut down. And further, even with that, let's say there's a 
long-running task out there. Even if you do _release, you might not be able 
to interrupt it properly so your resource-consuming task will keep running, 
_and_ you'll load a new copy of the same thing.

In this state, I'm not sure if I would even use it to hot-reload 
configuration variables (static, sync code), let alone async modules.

2. I guess it's early, but the docs and the API should be better. On the 
first read it was not clear to me what exactly I need to do. Especially 
since you rewrite modules in the same code where you try to explain dload. 
I would kick out that example and write something like this:

# Usage

const dload = require('dload');

const mo = dload.new();
mo.myHotModule = require('./my-hot-module');
// ... do some change to myHotModule, save the file
dload.reload();
// mo.myHotModule is reloaded.

Even your module name itself (dload) is confusing and not reflecting what 
it is for.

3. Use cases
It's not clear to me what is the usecase of this. You want to be able to 
load a module, use it, then _rewrite_ it from your own code, and then 
reload the changes? 

If I were to think of some use cases, I would say something like 
auto-reload is needed. Kind of like nodemon or supervisor, but reloading 
just those files. You'd give a list of files to watch, and then your server 
would not restart, only those modules would.
Or maybe you have some sandbox code, like for a live, web ide, but in that 
case I would never let that sandbox code in my main thread - because a 
simple setInterval(() => console.log()) will kill my main thread and not 
even let me reload the module. I'd rather spawn the sandbox code in a new 
process in such cases.

Such as it is, I would not use this module. If I need code reload, a simple 
restart is usually tollerant. And if my code is critical and I need online 
redeploy, I would use simple container tech for this, because that was it's 
purpose in the first place.

Please take the above as constructive critique. I love the idea, I just 
think you're not there yet (for me).

-- 
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/6e67e717-d87c-4575-bd54-3ab74e527fbe%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Re: outside for loop var value is undefined

2017-07-24 Thread Zlatko
The problem is that your last console.log line runs before anything else.

I don't see the rest of the code, but I suspect if you move your *return 
resolve(countRepetidos);* 2 lines up (right behind that *if(data.count>0) 
{}* block), your promise will resolve proper value.

Likewise, if you put the console log there, it's going to work.



On Saturday, July 22, 2017 at 3:50:01 AM UTC+2, Catia Matos wrote:
>
>
> 0down votefavorite 
> 
>
> I'm facing a problem with a value where inside my for cycle it has values 
> like "179" and outside i get always undefined. Why?
>
> var countRepetidos;if(obj.data.list!={} && obj.data.list.length>0){
> var aux = obj.data["list"];
> countRepetidos=0;
> for(var i=0;iDatabase.Probing.getMacAdress(aux[i]).then(function(data){
> if(data.count>0){
>countRepetidos++;  
>console.log("count repetidos 1",countRepetidos); // value 116
> }   
> });
> }
> return resolve(countRepetidos);}   
>
> console.log("count repetidos 2",countRepetidos);// value undefined
>
> log :
>
> 3|wscontro | count repetidos 1 1163|wscontro | count repetidos 2 undefined
>
> I try instead of use resolve, use callback but nothing... I saw other 
> answers in javascript but for node.js I cant resolve this problem... I saw 
> the link refering thus question as a duplicate but cant figure out a 
> solution to this case.
>

-- 
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/bff3ffb3-40e5-4d86-97fa-61e7e7536df1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Re: ShelljsExec return \n on parsing

2017-06-19 Thread Zlatko
You can try a simple parseFloat:

const balance = parseFloat(data);

Just make sure you get an actual number.

On Sunday, June 18, 2017 at 7:12:46 AM UTC+2, Woukaine Beyond wrote:
>
> Hi,
>
> I use this script for get my bitcoin balance : 
>
> app.get('/GET/MY/BITCOIN/BALANCE', function (req, res) {
> if( isConnected(req) == true)
> {
> var child = exec('cd /home/rpcdaemon/wallets/bitcoin-0.14.1/bin; 
> ./bitcoin-cli getbalance ' + req.params.account, {async:true});
> child.stdout.on('data', function(data) {
> var bitcoin_balance = data;
> res.send({"success":true, bitcoin_balance:bitcoin_balance});
> });
> }
> });
>
> the variable "bitcoin_balance" == 0.0 but return 0.0\n to my 
> json...
>
> How to fix it ? Thx !
>

-- 
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/78d2a968-11b2-4cf9-bb86-04dce51df497%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Re: Schedule function and leave the page nodejs

2017-06-16 Thread Zlatko
On Friday, June 16, 2017 at 3:43:09 AM UTC+2, Aaron Aben Danan wrote:
>
> I'm building a node.js app and I need to schedule a function and let the 
> user surf on my website. Is it possible ?
>
> If i wasn't that clear, here is an example :
> Let's say a user comes on my index page. From this index page I have to 
> schedule a function for tomorrow morning. The user continues his trip on my 
> website and leaves. The function is still scheduled
>
>
If I understand this correctly, you want the user to be able to trigger 
this scheduled function? Sure, it can be done, in many ways.

Super simple approach would be something like this:
1. create an endpoint which takes the necessary parameters and stores them 
into a database
2. create a separate module which:
  - runs periodically (e.g. every "tomorrow morning"),
  - checks for any scheduled tasks,
  - executes and marks them complete.

So if and when the user comes back, you can even show them the status (if 
you're tracking this by user).

Example:
// Express route for setting schedules.
const route = require('express').Router(); // express route you can mount 
wherever you need
const db = require('./my-db-setup'); // whatever you use here for the 
database.

route.post('/scheduled-jobs', function (req, res, next) {
  const job = new db.Job({
userId: req.user.id,
params: req.body.params,
ts: new Date(),
completed: false,
  });
  job.save()   // or however you save stuff to db.
.then(() => res.json({ message: 'Scheduled.' }))
.catch(next);
});
module.exports = route; // now import this in your main express router and 
mount it to /api or something.

// Than the executive module
const CronJob = require('cron').CronJob; // 
https://www.npmjs.com/package/cron or something similar
const db = require('my-db-setup');
const mySpecialFunction = require('./my-function'); // the actual code that 
you need to run.

// schedule the job for 8 am every morning
new CronJob('0 0 8 * * *', function() {
  // find all jobs scheduled before midnight that are not yet completed.
  // this will probably wary based on your db/orm of choice.
  const midnight = new Date();
  date.setHours(0, 0, 0, 0);
  db.find({
ts: {
  $lt: midnight
},
completed: false,
  })
.then((jobs) => {
  // simple forEach, but it might schedule a lot of "parallel" jobs - 
if there are many jobs, you'll 
  // probably block the server, so you might wanna get them one by one, 
or stream them from database, 
  // especially if you're running more than one instance of the Node 
process.
  jobs.forEach((job) => {
mySpecialFunction(job.userId, job.params)
  .then((result) => {
// if you have a callback, mark the job complete or save 
results or something
job.completed = true;
job.result = result;
job.save();
  });
  });
})
});

That's one relatively simple way to do your thing, there are a few things 
to watch for or adjust to your needs, but I guess you can start from here. 
You can use many databases here, even keep stuff in-memory (with some 
significant restrains, I recommend against it),  and different approaches, 
but you didn't share many details on your task. Ask (more) specific 
questions if you get stuck.

-- 
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/803e9578-8f64-4a12-b7bc-712b571b2158%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Re: NodeJS REST API

2017-05-19 Thread Zlatko


On Friday, May 12, 2017 at 1:19:26 AM UTC+2, Kameron Berget wrote:
>
>
> Should the require('mssql'), config and connect statements really be 
> inside the GET? That would mean that I have to repeat the config 
> (connection) settings in each method on each endpoint. Where would be the 
> best place to put this? Also, are simple sql.connect calls ok for large 
> loads or do I need to consider connection pools, etc?  My GET method is 
> below.
>
>
Well, for one thing, the *require* itself  is cached, on process level. So 
no matter how many times you call require('mssql'), it'll only read it 
once, at that first require in the first module that actually calls it.

But that is, as you seem to suspect, most likely *not* the perf problem, 
but the fact that on each API request, you have to create a new connection. 
How it is usually done is to have a *db* module somewhere. Then you export 
a *db.bootstrap* or *db.initialize* function, and possibly a *db.client* from 
that module and other db-querying modules use that client. You call the 
init once when your server is starting, and than all other actual calls to 
the db do not have to do this step. Just make sure that before the server 
started serving

One of the exceptions to this would be when you're using something like 
Azure Functions, or AWS lambda or similar. Usually you cannot persist 
database connections there so you have to connect on each request. But 
that's probably something you ask later.

One small disclaimer is that I didn't work with Azure, but I've worked with 
other bigger infra/platform providers and they usually share those concepts 
so I'm pretty sure the above should apply to Azure App service.

-- 
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/cdc779d3-56a3-4c23-a985-c6d9388c2671%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Re: how can i write a string data using fs

2017-05-19 Thread Zlatko
Few things, one really important:

*You shared your API token with the world!*

If you can, delete that token and in the future, replace it with a 
placeholder when you're posting examples.

Second, *request* you can handle errors in streams, e.g.

*request(options).pipe(fs.createWriteStream(filename)).on('error', err 
=> console.log(err));*

However, this is only a part of the solution - the problem is that request 
doesn't think that e.g. 404 response will be an error - it'll let you 
handle it. Check this answer: http://stackoverflow.com/a/14972828/162070

What it says is to check for the status code before creating your write 
stream, something like this:

const r = request(url)
r.on('response', function (resp) {
  if (resp.statusCode > 399) { // e.g. 400, 404 or whatever else you 
consider failure
throw new Error();
  }   
  r.pipe(new WritableStream())
});


-- 
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/ce340ce4-d6e1-40df-a623-0cd8a5ed13f3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Re: How common is it to restart a NodeJS app?

2017-05-07 Thread Zlatko


On Sunday, May 7, 2017 at 12:32:15 AM UTC+2, lawrence...@gmail.com wrote:
>
> Do you keep track of how often your app dies and is restarted? 
>
>
Nope, not directly. But I do scan the logs from time to time to check if 
there's something unusual (including restarts).

 

> Of the die/restart cycle, how much is deliberate on your part (an Erlang 
> style fail fast philosophy) versus how much is s a total surprise? 
>

I try to make any restart explicitly because of a new deploy. If my app is 
restarting on its own occasionally, it's a bug and I try to find it and fix 
it f I see it.
 


> For those of you who have apps that die often, what are the circumstances 
> that cause it to die often? 
>
>
Usually bugs. An uncaught error in init, somewhere where I rely on a 
third-party site and it's module, but those break and I didn't try/catch 
this (because I didn't read the docs and saw that they might, or because 
they didn't document it at all), things like that.

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/20bcccde-86c8-4e52-9646-5a4202dfeef7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Re: How to Improve Node .js performance

2017-05-07 Thread Zlatko


On Sunday, May 7, 2017 at 12:32:08 AM UTC+2, lawrence...@gmail.com wrote:
>
> I occasionally see things like this in the log, but this simply kills the 
> app. This does not return nicely formatted JSON, which just happens to lack 
> the right data. 
>
> It does, however, stall, for a very long time, sometimes 20 or 30 minutes. 
>
> [...]
>

This part looks like a simple case of a memory leak. Your code (or some 
library you use) is creating objects, but not releasing them, and at a 
certain point it time, your process is out of memory. 

That is relatively simple to debug. Install the heapdump module 
(https://www.npmjs.com/package/heapdump or something similar), and then 
dump the memory maybe once each hour. Something like this in your main 
script.

const heapdump = require('heapdump');
setTimeout(function() {
  heapdump.writeSnapshot(`/tmp/${process.env.pid}${Date.now()}.heapsnapshot`);
}, 60 * 60 * 1000);
// ... the rest of your code.


Then load up the dumps into Chrome's Javascript console (Dev Console -> 
Profiles) and see what kind of objects are you accumulating or not 
releasing).

(Make sure you have enough disk space for all the heap dumps. Also, 
depending how often your app gets stuck, you can dump more or less 
frequently, this is just a basic example.)

On the other hand, it might not be the memory leak, maybe your app is 
specific and simply needs more memory to function properly under load. But 
I'd bet on the mem leak.


-- 
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/91bf6f7c-8c65-4a4f-a4d9-c58e992761f1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Re: Why would a NodeJS app give bad data when it is under stress?

2017-05-04 Thread Zlatko

>
>
> Any thoughts on why this might happen when the load is high enough? 
>
>
Interesting read! I would love to see that code, this way I can only 
speculate that even though you think your code is all synchronous, it is, 
in fact, not. Perhaps one of the functions or libraries has an implicit 
timeout where it then fails silently?

Or maybe you've exhausted the heap but hit some yet undiscovered V8 heap 
edge case where the it can get mixed up if your contexts get shuffled 
around a lot. I'm thinking - you allocate a certain amount of memory for 
those 4 GB of data, but if you're bombing the API, Node might be holding 
thousands extra sockets open which is taking another chunk of memory that 
you didn't account for - and than one of your scoring functions can't 
allocate enough to work?

Did you test this with always hitting the API with the same example? Does 
it get confused in that case too?

Anyway, I don't know how viable it is, but maybe hooking up Chrome dev 
tools and setting a breakpoint at those filters and searches could shine 
some light.

-- 
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/a21852f0-5176-4369-9bba-5d536be6c0f9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Re: Export variable - ExpressJS

2017-05-04 Thread Zlatko

On Wednesday, May 3, 2017 at 11:55:59 PM UTC+2, Peter B. wrote:
>
>
> I need your help. I'm working on a project and I have a problem with the 
> fact that nodejs is asynchronous.
> I want to export my variable called 'macAd'. But even with a global 
> variable, I can't do it. 
>


If I understood correctly, you want to export macAd? But later you don't 
see this variable? Well, it might take a few words to explain, but it's a 
simple thing really.
The problem is if you do something like:

let macAd; // *undefined*
module.exports  = macAd; // again, *undefined*
macAd = 3; // doesn't matter now, because the exports is bound to 
*undefined* already

if you require it later, you'll get *undefined*, not a reference to your 
variable. It's passed by value.

But if you export an object instead, you can modify that object later (say, 
by setting a *macAd* property), without changing the reference to the 
object - which means whoever required the module will get to resolve the 
value after you set it.

Have your module set up like this:

const macAd = require('macad')
const obj = {
  macAd: undefined,
};
module.exports = obj;
// Now the export has a firm grip on our object. EVen if the value is 
undefined itself, the object is there and it'll be
// useful later.
console.log(obj); // -> { macAd: undefined }; 

macAd.getMac(function (err, mac) {
  // obviously handle error first.
  obj.macAd = mac;
  console.log(obj); // -> { macAd: '::1' };
});




Then, when you require the module later, at first it's going to be 
undefined, but later it should resolve to your value. E.g.

const myModule = require('./whatever-you-named-it');
const TIMEOUT = 1000; // or however long the 'macad' module takes.
console.log(myModule.macAd); // -> *undefined*
setTimeout(function () {
  console.log(myModule.macAd); // -> *should give you ::1 or something.*
}, TIMEOUT);

Now you have a problem though, your module is async, but you're not sure 
when is it complete and when it's safe to use it. That TIMEOUT might be 
either too much for you or maybe too short if the computer is busy.

You can get around that by wrapping the *getMac* call in an initializer 
function, like this:

const macAd = require('macad')
const obj = {
  macAd: undefined,
  initialize: function () {
// I use a promise but yuou can go with a callback too
return new Promise(function(resolve, reject) { 
  macAd.getMac(function (err, mac) {
if (err) {
  return reject(err);
obj.macAd = mac;
resolve();
  });
});
  }
};
module.exports = obj;
console.log(obj); // { macAd: undefined, initialize: [Function] }

Now you can require a module, and call *initialize* on it, and you'll get a 
promise resolved (or rejected) when the *macAd* is available, like this:

const myModule = require('myModule');
console.log(myModule.macAd); // most likely *undefined*
myModule.initialize()
.then(function() {
  // now myModule.macAd is available.
  console.log(myModule.macAd); // ::1
})
.catch(console.error);

But here we have other issues. For one, you might simply call getMac 
directly elsewhere like this, there's no direct benefit in wrapping it in 
its own module. And another thing - every time you call your module, the 
getMac is going to be resolving. In this particular case it might not be a 
big issue, but what if it wasn't a *getMac*? What if it was something 
calling an expensive 3rd party service? You call it every time you call 
this.

That's why you basically store a reference to that promise, and only call 
the full init once - every other time you return what you already have.

const macAd = require('macad')
let initPromise; // by keeping it out of *obj*, you're keeping it private 
to the module itself.
const obj = {
  macAd: undefined,
  initialize: function () {
// first check if another module already called init - then just 
resolve what we have, they don't have to wait for *getMac*
if (initPromise) {
  return initPromise;
}
// if it *wasn't* already called, call macAd now and store the 
resulting promise in initPromise.
initPromise = new Promise(function (resolve, reject) {
  macAd.getMac(function (err, mac) {
if (err) {
  return reject(err);
}
obj.macAd = mac;
  });
});
return initPromise;
  }
};
module.exports = obj;

Hope this helps you out a bit.

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

[nodejs] Re: Node application - request & response

2017-04-20 Thread Zlatko


On Wednesday, April 19, 2017 at 2:42:02 AM UTC+2, SC wrote:
>
> Hi,
>
> I have a nodejs application, in which I am making a call to another rest 
> service.
>
> When I directly call that rest service from a simple request response node 
> application, it works just fine from the command line.
>
> But when I make the same call from the application mentioned above, I do 
> not get any response.
>
> What could be going wrong?
>
>
Without any code, it's hard to say. What are you making the call with? Does 
your simple request/response node app work as a cli module or how did you 
do it? Can you call the other rest API from node REPL?

The problem could be in your code, or it could be that some of the 
libraries you required that overwrote or changed functionalities you use.

If you have that working simple req/res node app, can you make it a module? 
Super simple module - just export a "run" function, and then call that 
module/function from your main app - just to see what's going on. If this 
works from, say, cli, but not from your app, it's most likely that your 
main app changes some functionality that you use.

-- 
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/3f81aaee-1bae-4566-80b0-10267dca4b8f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Re: Can we Run an app with Node Js on Mobile ?

2017-03-01 Thread Zlatko
On Tuesday, February 28, 2017 at 6:35:59 PM UTC+1, Manpreet kaur wrote:
>
> My basic requirement is to build an app  with nodejs that can run on 
> desktop and mobile also.So is its possible to Run Node on Mobile and what 
> would the possible solution for it?
>

Depending on what specifically you need, you can take a look at Electron 
(https://electron.atom.io/). It has Node built in, and there are various 
ways to target the build to various desktop and mobile platforms.

But you have to be more specific in what are you trying toi build to get 
specific details.

-- 
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/01ac26c1-713b-47e9-9ee4-28514b8c117a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Re: Store images in node.js express web site

2017-02-07 Thread Zlatko


On Monday, February 6, 2017 at 9:29:21 PM UTC+1, אלה וייס wrote:
>
> .
> I put my images in a directory  inside node.js public folder
>
>  :in order to be able to read all images from folder using $.ajax
>
> (((app.use('/albums',serveIndex(path.join(__dirname,'public/AlbumImages
>
> (((app.use('/albums',express.static(path.join(__dirname,'public/AlbumImages
>
> My question is:
>
>  ?In case I have images on *another server *,How can I do the same
>
>
Technically, yes. But the question is why, of course.There are multiple 
ways to have this done, depending on your use case:

- If those are simple, static assets, you might want to skip node 
completely - just tell your nginx, load balancer or whatever to route 
requests for images to another server.
- Alternatively, maybe you wanna process access rights before you serve 
those - e.g. user can only have his own images. You might have image URLs 
in the database, and Express only has an endpoint that serves you the links 
to those images. Then the client fetches those from the locations given.
- Or maybe you actually do want to get images from another server. Again, 
we must branch off.
- you access them some other way? E.g. via samba or some other networked 
file system? Then as long as the remote file system is mounted locally, use 
the same or similar approach to what you have. Maybe just stream the images 
instead of serving directly, to avoid buffering whole images in your 
express app.
- Are the pics available via HTTP? Then something simple like 
app.get('/albums',  (req, res) => require('request')('http://remote-url/' + 
req.url).pipe(res));
- some other means of access? Well, simple - take your request, then you 
yourself request the remote file, then pass on the response or response 
stream to your client.

Maybe you can share more details on what exactly is your use case?


 
 

-- 
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/64c351d8-bc19-4491-9902-2a8d3a65e32f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Re: How to communicate 2 node server with high performance.

2017-02-07 Thread Zlatko


On Monday, February 6, 2017 at 9:29:07 PM UTC+1, Arun Kumar Raga wrote:
>
> Hi All,
>  
> 1) How can i share the global variables in node cluster environment, 
> Currently i am using *NEDB 
> *
>  for 
> global data and running in another server and communicating both MAIN 
> server and NEDB 
> 
>  
> Server(global data) using http request(facing this issue 
> ).
>
>Is their any better approach is their to communicate two nodejs server 
> *or* Any better approach to keep global variable data(last state 
> persistence).
>
>

If I read that correctly, you're using node-cluster or similar clsutering 
technique and want some global state. You already provided an answer, you 
need an external persistence store. That can be something like what you're 
using (but with persistence enabled), Redis, an external database, like 
MongoDB or similar, even filesystem. Just make sure that your chosen 
solution doesn't allow for stale records (or decide you can tolerate some) 
and see what's the best option for 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+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/50826d2e-8db2-4a45-9824-3eab6da1a1a9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Re: Advice please .... risks with "no standard" manipulation of packages in node_modules

2016-12-01 Thread Zlatko

On Wednesday, November 30, 2016 at 6:46:33 PM UTC+1, Tom Fennelly wrote:
>
> Hi.
>
> I'm just wondering what might be the risks associated with manipulating 
> the contents of the node_modules folder outside the normal "npm install" 
> etc commands. IOW ... are there reasons why the a raw "drop in" of packages 
> into the node_modules is a bad idea Vs doing it through the normal "npm 
> install" mechanisms?
>

TL;DR: it's not a problem if you replace *npm-cli* tool with another 
capable tool. 
 
It's basically about convenience. For example, if you've tried yarn (the 
Facebook's new thingy and npm-cli replacement), it messes up with your 
node_modules. If you try some npm modules themselves, they can do it too 
(for example: fix-dropbox-node_modules-symlinks).

Having your module version numbers in package.json, now that's the real 
deal. What does npm-cli offer:

- keeps track of versions and updates stuff for you,
- takes note of what's a prod dependency, what's a dev dependency, peer dep 
etc,
- allows for cross-platform stuff.

There's more stuff, but these are, I think, the most important points.

The way I see it, only the last thing might bite you hard, but let's go 
over those points.

1. Versions and updates
Like I've said, yarn does package version management. Bower does it too. 
Many tools do, even Sublime or WebStorm can do it for you. The thing is, 
pick a good thing that you can repeat in production environment and on 
every dev's workstation, and you're probably ok. If your tool can *also* update 
package.json, you're golden - even people who don't use your tooling can 
probably repeat your steps (or run your one-liner install/setup/config 
script).

As for updates - if you're "manually" (or by other tool than npm-cli) 
updating a package version, but still plan to ship without node_modules, 
you might lose the correct package version. If your other tool is 
automated, you can simply reuse package.json or something like that, but if 
you're getting a new module by actually downloading it and saving into 
node_modules/, you might forget to update your package management.
So, unless you ship node_modules/ directory with all your code, this might 
be a problem. Again, tools like yarn can update on their own, so no issue.

2. Dev, prod, test, peer etc dependencies
Ah, basically the same. If your replacement tool supports this, no risks. 
If it doesn't, the risk is again that prod doesn't get a critical module or 
that devs work with different versions of modules or simply that your git 
repository is huge and checkout and deployment takes forever.

3. Binary modules
Say you're installing redis and hiredis. hiredis is a binary package. If 
you drop in your own version manually, and you're actually shipping the 
node_modules/ folder, your colleague might be using a mac or windows (guess 
what I'm using :P), so it won't work for them.
But again, tool that takes care of it, takes the pain away.


-- 
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/07e0757b-d736-4ecf-83d6-5a00caa6519c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Re: Tips for finding runaway CPU bugs

2016-10-12 Thread Zlatko
Although it's a CPU issue, a heapdump could still be useful. There are ways 
to do it, such as https://www.npmjs.com/package/heapdump. You can try to 
get a dump once the CPU goes up and simply load it into Chrome dev tools - 
to see what is going on, perhaps there's a hint.
If while at 100% you can't get a dump, you can try doing increments, like 
every ten seconds or so and then see what changed closer to the problem.

Even better would be if you could run with debugger directly -something 
like the new `node --inspect server.js`, but that depends on where your 
servers are, how you run them etc.

On Monday, October 10, 2016 at 3:53:03 PM UTC+2, Bgsosh wrote:
>
> Hi,
>
> I'm having a tough time tracking down an issue we currently have in 
> production.  Our node processes will sometimes suddenly spike in CPU usage, 
> and then stay pegged at 100% until restarted.
>
> I'm not able to reproduce on development machine.  Could anyone offer any 
> tips for tracking this down?  Any advice would be appreciated as I'm 
> currently not getting enough sleep!
>
> Thank you
>
> Bg
>

-- 
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/6ab0ae46-c693-4c64-8e86-e362eadff873%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Re: Business objects retained by Global Handles in heap dump

2016-10-10 Thread Zlatko


On Sunday, October 9, 2016 at 7:56:11 AM UTC+2, Russ Frank wrote:
>
> I have a heap dump (obtained with bnoordhuis/node-heapdump) of a 
> production node process that had a large heap. I found a bunch of business 
> objects retained by "(Global Handles)". I'm wondering how a JS object can 
> end up being retained in this way. Would it need to go through a native 
> extension which is accidentally creating such a global handle and thereby 
> retaining the object?
>
>
I don't think it needs a native extension there - a simple variable leak 
can do that. Some code analysis tools can help you check your javascript 
parts for such issues, not sure about the extension. Is that something 
occurring regularly? 

-- 
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/34fe1ad6-d852-4335-8af7-49177bdc02c7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [nodejs] Re: Question is this possible

2016-10-08 Thread Zlatko Đurić
Oh, so you want to distribute a dashboard to a few devices :) What a
marvelous idea! So, let's play with it, I'm already enjoying this!

I'd say your key data structure is a "Car". It has a few "sensors", a
"PIN", and a list of connected "display devices".
If it has devices (phones) connected, it will, in order of priority, send
each of them just one specific type of sensor output. It will also tell
that device which output it is.

Example: no phones - no output. Then a single phone connects to the server,
and gives this car PIN. (Could be a password, token, QR code, whatever, I'm
simplifying here).
When the server sees this PIN, it starts sending to this device the most
important output (engine/coolant temperature, let's say). And if you're
using something like websockets, or server-sent events, or push or by
simple long-polling, it updates this data frequently or in real time,
depending on your sensor inputs.
Then the second phone connects, with the same PIN. The server sees the
second device, it sends it the _second_ type of sensor output, and starts
pushing data - in our case, speedometer.
And so on - as new devices connect, they are assigned a different sensor
output and they start showing it.

Devices, ideally, should know how to display all of the outputs, but only
show the selected one, the one they receive (because you can't control the
order of devices connecting). Alternatively, devices can ask for just
specific sensor (e.g. RPM or signal lights) and the server will still keep
track of which output to show to which device. You can connect more then 5
phones, and server tells the extra ones to be on "stand-by" - if one of the
busy phones disconnects (e.g. battery empty), server tells one of the
stand-by ones to chime in.

I mean, you can go way less than that, for a basic functionality, or much
more complex, depending on what you need.

But yes, you can definitely do it and node could be the best tool for the
job.


On Thu, Oct 6, 2016 at 4:58 PM, thebluearchernc <jrwei...@gmail.com> wrote:

>
> <https://lh3.googleusercontent.com/-qv26_VPYcLE/V_ZloAAivrI/AJM/2zeigtQLmMA4JUunuPQGxxambHRbcbFlQCLcB/s1600/test%2Bdash.bmp>
>
>
> <https://lh3.googleusercontent.com/-qv26_VPYcLE/V_ZloAAivrI/AJM/2zeigtQLmMA4JUunuPQGxxambHRbcbFlQCLcB/s1600/test%2Bdash.bmp>
> Well i am new at this so no i did not know i did not need separate ports
> but you are correct  i wish to show part of the page on each devices  with
> the devices lined up to make a larger display  sort like this image with
> each display containing a section of the dash
>
> any pointers to where to begin will be greatly appreciated  at this point
> i do not know the exact amount of display i will need  just want to make
> sure this can be done.
>
>
>
>
>
> On Thursday, October 6, 2016 at 10:41:41 AM UTC-4, Zlatko wrote:
>>
>> Having 5 devices connect to different ports is fine, not a problem, but
>> *why* do you want separate ports?
>>
>> You can have a single page and have it split into sections and have them
>> all update. You can, at the same time, have 5 things connected somewhere.
>> You can even make a link between those connections and the sections on the
>> page.
>>
>> But what you're describing is very vague, so whether your specific idea
>> is possible cannot yet be answered. However, create a digital dash for an
>> automobile definitely can be made, with Node or whatever else. (I know
>> because I was working at a connected car startup and we did these things
>> with Node).
>>
>> So - about that page. Where do you wanna show this dashboard - on each
>> android device or each device gets its own "section" of the page? I'm
>> assuming you want to link 5 devices to the 5 page sections - why do you
>> need separate ports? You can have a single app listening on single port,
>> but keeping track at which and how many devices are connected. And you can
>> have the app also keep track of those "sections" of the page, and update
>> accordingly.
>>
>> So, share more details for more detailed answer, please.
>>
> --
> 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 a topic in the
> Google Groups "nodejs" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/nodejs/TPIPuh1TieE/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> nodejs+unsubscr...@googlegroups.com.
> To post to this group, send

Re: [nodejs] how to link to installed node packages / modules from another dir

2016-10-06 Thread Zlatko
As Ryan said, you can install the "shared" modules at a common parent 
directory. So if you have /*dir1/app1 *and /*dir2/app2*, you *could* have a 
/node_modules folder with those shared directories.

However, it seems like a bad practice, updating one app might break the 
other. Are you trying to save disk space with this or reduce install time 
or something else entirely?

-- 
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/dbfa8e78-ad12-4738-ae2c-63d3919e0772%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Re: Returning binary data

2016-10-06 Thread Zlatko
Maybe Buffer.from(arrayBuffer) seems like it could help?

https://nodejs.org/api/buffer.html#buffer_class_method_buffer_from_arraybuffer_byteoffset_length

Basically a buffer from a typed array. Then stream that to client. 

-- 
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/80a2b5e3-abe2-40f4-9668-8f4ff3e988ba%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Re: Question is this possible

2016-10-06 Thread Zlatko
Having 5 devices connect to different ports is fine, not a problem, but 
*why* do you want separate ports?

You can have a single page and have it split into sections and have them 
all update. You can, at the same time, have 5 things connected somewhere. 
You can even make a link between those connections and the sections on the 
page.

But what you're describing is very vague, so whether your specific idea is 
possible cannot yet be answered. However, create a digital dash for an 
automobile definitely can be made, with Node or whatever else. (I know 
because I was working at a connected car startup and we did these things 
with Node).

So - about that page. Where do you wanna show this dashboard - on each 
android device or each device gets its own "section" of the page? I'm 
assuming you want to link 5 devices to the 5 page sections - why do you 
need separate ports? You can have a single app listening on single port, 
but keeping track at which and how many devices are connected. And you can 
have the app also keep track of those "sections" of the page, and update 
accordingly.

So, share more details for more detailed answer, please.

-- 
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/70031fa8-fcc4-4947-b7ff-bc39635e5f46%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Re: Multiple timeouts (lots of...)

2016-09-19 Thread Zlatko
5000 timers per se should not be a problem to measure nor a problem to the 
app. It's not even a strain to the connections: it amounts to approximately 
83 pings per sec, which is not too much.

But the bigger question is why do you want this? Just to keep sockets 
alive? You can set this option in your websocket implementation of choice 
(well, the most used ones, at least). Tell ws to do it's own keepalive and 
you don't have to do bookkeeping.

If it's to relay changes in some sort of state to all the clients, then 
again - why not simply sending updates as they happen? That's kind of the 
advantage of websockets - if you wanted timers, you could simply schedule 
regular REST requests on the client and not mess with all of this.

-- 
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/7a7d5f0b-e60f-4243-b510-fd52f94372f8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Re: What is the best way for JavaScript to access data from Node.js/

2016-09-19 Thread Zlatko
I suspect your last line is the actual question?

On Sunday, September 18, 2016 at 1:28:38 AM UTC+2, ABC DEF wrote:
>
>
> Would the best way to be to set a variable in HTML to "input" and get Node 
> to write the data to it when it is received, and somehow get JavaScript to 
> read that variable and set it blank when it is done with it? Some intuition 
> would be appreciated. Thanks.
>

That actually depends on what you want to do.

One way to do this is, fetch data from a "distant Java server" with Node 
and prepare a HTML page that your clients (browsers) will consume. Example, 
to set an input value, you would create:

- a *fetch-data.js* service, to fetch data from the distant Java server:

import request from 'request';
const distantJavaServerUrl = 
'https://distant-java-server.com/api/endpoint-for-your-data-in-invalid-format'
;

export function fetchData() {
  return new Promise(resolve, reject) {
request('http://www.google.com', function (error, response, body) {
  if (!error && response.statusCode == 200) {
// Assuming this is JSON data:
resolve(JSON.parse(body)); // or format it better
  }
  reject(new Error('Upstream error.'));
});
  });
}


- a *views/my-file.ejs* html template (omitting a lot of boilerplate):







- a node.js server and handler for requests for this file:

import express from 'express';
import { fetchData } from './fetch-service';
const app = express();
app.set('view engine', 'ejs');

app.use(function(req, res) {
   fetchData()
  .then(data => res.render('my-file', data))
  .catch(err => res.status(500).send('Server error.\n'));
});


app.listen(8080, () => console.log('Listening on 8080')); 

You can then get your HTML with data here:
[zlatko@zlatko-desktop ~/tmp]$ curl localhost:8080






[zlatko@zlatko-desktop ~/tmp]$


Now, by playing more with your fetch-service.js, you could transform the 
data in the way you like it. Playing more with the .ejs file, you can 
format the input, you can name it, add buttons and styles and javascript 
and other things that make a web page a web page.

Now, how to "read and clear a file/variable which Node also can" is a valid 
question, too, but it's more of a frontend question better answered on some 
frontend group.

Now, this is all very basic because you're not asking a specific question. 
So although JavaScript and Node.js are not very limited in what they can 
do, it might be challenging if you don't know what you want to achieve. So 
I would recommend studying a Node.js application design, maybe by following 
a good book, a video tutorial or other resource would help overcome that 
challenge.


-- 
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/e1fefdf6-b7a0-42e7-9d37-7241c8324bb8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Saving multiple files using Promises

2016-08-28 Thread Zlatko
You seem to be passing 2 args to your addresses.map() callback ( can't tell 
exactly on phone:(). But if you do, the second arg is simply used as function 
context ('this'). You don't use it so it's never called.

Perhaps try something different:

Promise.all(addresses.map (item => getMap(item)) 
.concat (addresses.map(item => getSateliteMap(item)));

That would fire all requests in parallel, so maybe you should make sure to 
limit your batch size. Probably a wrapper for this function which chunks up the 
array into batches and runs the batches in series, and informs the original 
request when everything was returned.

Additionally you might consider not rejecting that error; that seemingly 
terminates all other requests without waiting for their results. Maybe instead 
write down which reqs failed and in the end you will have more details on how 
things went.

-- 
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/d46c42e7-7704-4da1-b68c-1a8e8b99e55f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Re: [weird] console.log is not sync anymore when I use a stream, output is truncated when it s followed by process.exit

2016-05-24 Thread Zlatko
On Monday, May 23, 2016 at 4:57:29 PM UTC+2, mh-cbon wrote:
>
> Hi,
>
> I m facing a badly weird issue which i can t tell if it s a bug, or an 
> error from my side.
>
>  
It's not a bug, it's a feature :)

Seriously, *console.log* is *asynchronous*, because it can involve disk I/O 
(e.g you run a program but redirect the log to a file). In order not to 
block with such processes, console.log is made async.

IIRC *console.error* is sync - so in this particular case you can use that. 
But you can also write to process.stdout and then make sure your stuff is 
written before you end the program.

-- 
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/aef2960d-f70b-405b-8255-756cdf9c2885%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [nodejs] Re: child_process and scaling

2016-05-21 Thread Zlatko Đurić
You should try it. But the bottom line is, in a thousand-reqs-per-sec
scenario, you'll almost always hit a bottleneck and need to scale the
processing job over multiple machines. So it's a tradeoff - how important
is it to you to finish every request, how fast you want results, is the
1k/sec throughput constant or peak... your imagemagick (or phantom binary,
whatever you use) can only run so many instances on a single machine.

So again - test your load such as it is. If you already have a sample JSON,
write a node script to make a png out of it - parsing json and calling
imagemagick should not take very much time. Then run the script 1k times in
a row and see how fast it goes. Then run it in thousand parallel shells and
see if that goes well, too.

testing, testing, testing. Hope I'm not too boring with it.


On Fri, May 20, 2016 at 11:33 PM, Ω Alisson <thelinuxl...@gmail.com> wrote:

> Interesting. I wonder if it is better to use phantomjs for the PNG
> rendering. Although it is slower, I don't need child_process
>
> On Fri, May 20, 2016 at 5:42 PM Zlatko <zladu...@gmail.com> wrote:
>
>> You have multiple things there. Thousands requests (per second, I assume)
>> is a lot even without spawning a child shell. Thousands of spawned shells,
>> even without image magick, can bring a busy system down. But then again,
>> you will know best with a test. Try it and see if and where you get stuck.
>>
>> Even if the system itself handles it, depending on how fast you get to
>> your saturation limits, your response time may get increasingly longer. If
>> that's acceptable and you know there will be downtimes when the jobs can
>> catch up, you might do well with this.
>>
>> The bigger problem I see there is that you cannot scale horizontally
>> there. You wanna be able to send those convert jobs to other machines as
>> well, probably. And for that, a simple child_process won't do, it would be
>> better if you had some sort of a job queue (MQ, redis pubsub, something of
>> the sort depending if you can allow failures and lost jobs). Then your
>> service that listens for reqs only shoots them to the queue, and listens
>> for a matching response on the response queue. And your actual png
>> generation service can listen on the other side and only take as many
>> requests simultaneously as it makes sense - e.g. maybe per num of CPUs or
>> similar, test there and see what makes sense. And when you have a lot of
>> work, just spawn another png generator on a new machine and you're good, no
>> blocking.
>>
>> The best thing to do is simply measure. Try to run several processes at
>> once and shoot a thousand requests, see how long it takes for all of them
>> to finish. Thn try to fire 10 waves of 1k reqs, each wave 2 seconds apart,
>> and see how that goes. (Of course, adjust the numbers to your environment.).
>>
>> Lastly, from my personal experience, these kinds of things regularly grow
>> out of hand and original specs, and it's better to just do job queues from
>> the get-go.
>>
>> Hope that helps.
>>
>> Zlatko
>>
>>
>> On Thursday, May 19, 2016 at 11:51:46 PM UTC+2, Alisson Cavalcante Agiani
>> wrote:
>>>
>>> I need to develop a service where the user sends an array of values, I
>>> generate a chart with d3.js and convert it to png with a child_process
>>> calling imagemagick to send it back to the user. Are there any caveats for
>>> child_process when scaling for thousands of requests?
>>>
>> --
>> 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/09ff5e6e-f2fe-45d7-bb57-488230ee78d0%40googlegroups.com
>> <https://groups.google.com/d/msgid/nodejs/09ff5e6e-f2fe-45d7-bb57-488230ee78d0%40googlegroups.com?utm_medium=email_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
> --
> Job board: http://jobs.nodejs.org/
> New group rules:
> https://gist.github.com/othiym23/9886289#file-moderation-policy-md
> Old group rules:
> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> ---
>

[nodejs] Re: child_process and scaling

2016-05-20 Thread Zlatko
You have multiple things there. Thousands requests (per second, I assume) 
is a lot even without spawning a child shell. Thousands of spawned shells, 
even without image magick, can bring a busy system down. But then again, 
you will know best with a test. Try it and see if and where you get stuck.

Even if the system itself handles it, depending on how fast you get to your 
saturation limits, your response time may get increasingly longer. If 
that's acceptable and you know there will be downtimes when the jobs can 
catch up, you might do well with this.

The bigger problem I see there is that you cannot scale horizontally there. 
You wanna be able to send those convert jobs to other machines as well, 
probably. And for that, a simple child_process won't do, it would be better 
if you had some sort of a job queue (MQ, redis pubsub, something of the 
sort depending if you can allow failures and lost jobs). Then your service 
that listens for reqs only shoots them to the queue, and listens for a 
matching response on the response queue. And your actual png generation 
service can listen on the other side and only take as many requests 
simultaneously as it makes sense - e.g. maybe per num of CPUs or similar, 
test there and see what makes sense. And when you have a lot of work, just 
spawn another png generator on a new machine and you're good, no blocking.

The best thing to do is simply measure. Try to run several processes at 
once and shoot a thousand requests, see how long it takes for all of them 
to finish. Thn try to fire 10 waves of 1k reqs, each wave 2 seconds apart, 
and see how that goes. (Of course, adjust the numbers to your environment.).

Lastly, from my personal experience, these kinds of things regularly grow 
out of hand and original specs, and it's better to just do job queues from 
the get-go.

Hope that helps.

Zlatko


On Thursday, May 19, 2016 at 11:51:46 PM UTC+2, Alisson Cavalcante Agiani 
wrote:
>
> I need to develop a service where the user sends an array of values, I 
> generate a chart with d3.js and convert it to png with a child_process 
> calling imagemagick to send it back to the user. Are there any caveats for 
> child_process when scaling for thousands of requests?
>

-- 
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/09ff5e6e-f2fe-45d7-bb57-488230ee78d0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Re: Problem in running nodejs script in mininet host.

2016-05-05 Thread Zlatko


On Wednesday, May 4, 2016 at 5:35:40 PM UTC+2, Reshma Roy wrote:
>
> Hi,
>
> I tries to run a nodejs code in a mininet host nodejs code.js and the 
> error i gets is follows :
>
> events.js:72
> throw er; // Unhandled 'error' event
>   ^
> Error: connect ECONNREFUSED
> at errnoException (net.js:901:11)
> at Object.afterConnect [as oncomplete] (net.js:892:19)
>
> Please help me to resolve this issue.
>
>
>
You're obviously trying to connect somewhere where you don't have access - 
a wrong database config maybe? Or an external API? But it's imposible to 
say without seeing what are you deploying - more of the code. 

-- 
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/61c240d9-4c2b-4c76-b41e-928dc7b0dbd9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Re: REST API

2016-04-30 Thread Zlatko


On Wednesday, April 27, 2016 at 5:05:43 PM UTC+2, Sirine Ibn Fraj wrote:
>
> Hello everyone ,
>  
> I am trying to retrieve data from a REST API in the server side (*.js) and 
> display it in my view (*.jade) 
>  
>
> I was able to get the data but was not able to send it to the view . 
> This is how my code looks like : 
>
>
>  var reqGet = https.request(optionsget, function(res) {
> console.log("statusCode: ", res.statusCode);
>   res.on('data', function(d) {
>   console.info('GET result:\n');
> 
> BugData =d ;
> console.log(d);  
> 
> }); 
> 
> }); 
>  
>   reqGet.end();
>
>
> BugData (was defined before )is the variable i am trying to send to the 
> view but for some reasons it is empty and does not contain the variable 'd' 
>
>
> Does anyone know why or how can i solve this ? 
>
>

I will assume that your console.log(d) line displays expected results.

But there's another question: where is your jade and and how do you call 
the render function? Without seeing those, especially the part where you 
call render (together with the BugData part), we cannot help 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+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/db3f53d0-0c62-4155-afe9-8e0aa0ca1a85%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Re: Delay a Node Stream Transform process

2016-04-27 Thread Zlatko
Depending on how you implemented the transform stream, the pipeline should 
be balancing itself automatically. How did you implement the stream? Do you 
use object mode? Did you try to do something with highWaterMark?



On Tuesday, April 26, 2016 at 6:34:05 PM UTC+2, Kayode Odeyemi wrote:
>
> Hi,
>
> I'm streaming data using the following data flow:
>
> Source(Database) -> Transform (An HTTP request) -> Sink(Database)
>
> Obviously the HTTP request task is a blocking task. At the moment, it 
> seems the Source is faster than the Transform process.
>
> How do I make the Transform process delay or better still work in tandem 
> with the Source or much better make the source delay until the current 
> transform task finishes?
>
> Appreciate your help.
>
> Thanks
>
>

-- 
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/791f9e72-c9e6-458f-bad7-04496ffd9505%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [nodejs] calling a nodejs express REST service with into url

2016-04-06 Thread Zlatko


On Monday, April 4, 2016 at 3:11:15 PM UTC+2, Adrian Albu wrote:
>
> Yes but the problem is that they were using an old api that somehow worked 
> with this type of call and my new api has new REST calls but should work 
> also with the old ws type of calls, so when I did it I had example calls 
> and didn't see they also can use some with  instead of &.
>
> Old api was in php and they didn't have this problem, it seems.
>
> To tell them now they have to change the way they did some calls is a bit 
> hard because of political shit.
>
>


Yes, I understand this part, it can be. But what did the PHP API look like 
- you do have access to that? Go see how they parsed the url.

Then I'd advise something like this (that's what I would do):

- if the PHP API does something weird: 
1. Copy the weird behavior in your new API - add it to a simple middleware 
that fixes URL params.
2. Place your new, proper route under `/api/v2/call`
3. Put your middleware and then the new API endpoint under `/api/v1/call`.

(Or some variation of that).

Then you can tell them - "hey, our old API was defective in this way, sorry 
you had to use that behavior. It's now under legacy endpoint there, but you 
can use proper calls here, we'll be developing new stuff under there in 
future."

If PHP API didn't do weird stuff and if it's simply weird in itself, then 
just write a parser for the req.url as a middleware which extracts your 
needed params. I'd still keep the legacy/v2 approach though.


-- 
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/30020e01-6eb3-47a0-9bf1-177a8e6083ec%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [nodejs] calling a nodejs express REST service with into url

2016-04-01 Thread Zlatko


On Friday, April 1, 2016 at 8:20:04 AM UTC+2, Adrian Albu wrote:
>
> That is not possible since I have no responsibility on that application, 
> belongs to another company and so on...
>
> I know is crap they encode the url so or something but... 
>

It's not crap. They're simply not following your API correctly.

Your API:
p1: string
p2: string

Valid call: ?p1=v1=v2.

>From your example (https://localhost:8080/rs?p1=v1p2=v2;), they 
only set p1 parameter, to "v1 
". They also set an "amp;p2" 
parameter to "v2", and finally, they set an undefined "amp" parameter. Tell 
the client to also set the v2 parameter, and your call will work.


 

>
> vineri, 1 aprilie 2016, 06:14:35 UTC+2, ryandesign a scris:
>>
>>
>> On Mar 31, 2016, at 9:12 AM, Adrian Albu wrote: 
>>
>> > having built an express REST api got a problem when one of the clients 
>> is calling one service with encoding the & to  
>>
>> Fix the client to not do that. 
>>
>>
>>
>>

-- 
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/4e44a696-ed75-400c-97e6-875975583833%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [nodejs] A few newbie questions on Nodejs

2016-03-24 Thread Zlatko


On Thursday, March 24, 2016 at 6:43:50 AM UTC+1, Harry Simons wrote:
>
> On Thursday, March 24, 2016 at 7:51:35 AM UTC+5:30, Matt Sergeant wrote:
>>
>> On Wed, Mar 23, 2016 at 12:25 PM, Harry Simons  
>> wrote:
>>  
>>>
>>> For example, if an isolated and primarily an I/O bound request takes, 
>>> say, 3 seconds to get serviced (with no other load on the system), then if 
>>> concurrently hit with 5000 such requests, won't Node take *a lot* of 
>>> time to service them all, *fully*?
>>>
>>
>> What is taking 3 seconds? The answer, as with all technology is "it 
>> depends". If you block the CPU for 3 seconds then yes of course, your app 
>> will suck. If you're just sitting waiting on other I/O (e.g. a network 
>> request) for 3 seconds, then lots can happen in the gaps.
>>
>
> A CRUD operation against a large database could take well > 3 seconds. I 
> was assuming the DB server being co-located with the Node server (on the 
> same physical box) in my original question and was thus taking it to 
> involve CPU+I/O processing instead of just network I/O; the latter would be 
> the case if it were another physical server on the network (as in your 
> response). Apparently, that's a bad idea even with an evented platform such 
> as Node. Ben's response too assumes a remote DB server resulting in a pure 
> I/O wait on the Node server. I get it now.
>

If you have a CRUD operation that takes well over 3 seconds, then this 
RDBMS would definitely benefit from its own dedicated box. And if you're 
serving that same query to those 10,000 concurrent users, then your _app_ 
processing time is probably irrelevant, be it Node, Python, Java or good 
old PHP. But you're talking scalability and comparing to apache, so let's 
compare: Node on its own - takes many requests. Apache - not so many. 
Database query duration time: lasts the same. That's where node defends its 
claim for "insta-scalability".
 

>
>  
>
>> If this 3-second task happens to involve exclusive access to the disk, 
>>> then it would take 5000 x 3 sec = 15000 seconds, or over 4 hours of wait to 
>>> see the response for the last request coming out of the Node app. In such 
>>> scenarios, would it be correct to claim that a single-process Node 
>>> configuration can 'handle' 1000s of requests per second (granted, a 
>>> thread-server like Apache would do a lot worse with 5000 threads) when all 
>>> that Node may be doing is simply putting the requests 'on hold' till they 
>>> get *fully* serviced instead of rejecting them outrightly on initial 
>>> their arrival itself? I'm asking this because as I'm reading up on Node, 
>>> I'm often hearing how Node can address the C10K problem without any 
>>> co-mention of any specific application setups or any specific application 
>>> types that Node can or cannot handle... other than the broad, CPU- vs 
>>> I/O-bound type of application classification.
>>>
>>
>> I think you've just generally misread a lot of stuff about this, 
>> honestly. Disk I/O is "complicated" in node (because async I/O to disk is 
>> complicated in operating systems, it's not Node's fault). But not many web 
>> apps use the "fs" module on their requests directly. Node uses a thread 
>> pool for the filesystem requests on Unix-like OSs, so there are limits 
>> there, but it's very rare to see that as an issue for developing node apps 
>> at scale. When you talk to any of the DB modules you're using network I/O 
>> in Node, not filesystem I/O.
>>
>
> I took up the specific case of the DB server co-located on the Node 
> server. Apparently, even in a Node-based application this would be a bad 
> idea - is what I'm hearing. Which is fine. I get it now.
>

It's not necessarily a bad idea, but it most likely is if you're serving 
10,000 or more concurrent users. Say you have some simple mostly-read 
database stored in memory. I'm thinking Redis which is commonly used. Node 
and this Redis instance can sit on the same server for those 10k requests - 
but we do not depend so much on Node here (provided the app was written 
relatively well) - we're depending on the server itself.
 
And that is, I believe one of the huge benefits of Node. You basically lift 
any such concurrency limits from your runtime environment and from your app 
and move it outside, to the underlaying host OS. You can be certain that if 
you have problems, it's not your app or Node that's the bottleneck - it's 
the database system, disks or something similar.
(Although, it often _is_ your app. Well, for me, at least, most of the 
scaling issues I've had were my bad design.)

-- 
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] Re: Protecting package dependencies from malicious code from npmjs.com

2016-03-24 Thread Zlatko

On Thursday, March 24, 2016 at 3:21:41 AM UTC+1, Chris Hills wrote:
>
> As I understand it, a package author can un-publish their package on 
> npmjs.com, and somebody else can publish a package with the same name. If 
> I create a package depends on a package from npmjs.org, I have little 
> protection against a "bait-and-switch" which could result in unwanted, even 
> malicious code being deployed and run. Other software distribution methods 
> usually involved signing with a private key to protect against this kind of 
> behaviour. Is there something I can do today to protect against this 
> without resorting to have to manually perform an audit every time I 
> download a package from npmjs.org?
>


A very popular question these days :) I'm also interested in something like 
that.

I had two ideas in mind, I wonder what others say about this:

1. Scoping packages

I was thinking something which would be a bit manual in the beginning - as 
you install a package, clone it into your scoped package 
(@username/package). I'm thinking a script could be made to do that, 
perhaps even an npm wrapper. Perhaps smart enough to check if you already 
have such a package.

But this feels quite wrong. It would duplicate a crapload of packages. 
Furthermore, if the script becomes easy to use and transient (which is 
basically the only way it could be useful), it would get spread and get 
used massively, potentially requiring npm to scale beyond anything 
reasonable (instead of 300,000 packages, good deal of which get duplicated 
for each of a humble estimate of a few million users - that would mean a 
whole lot more stuff to handle. The actual content would get deduped, I 
guess, but still feels like unnecessary burden.

2. Include packages in source control.

Basically add node_modules to source control. Then there's nothing to be 
installed, everything is already there. Not sure if and how much more 
complicated it gets when the code gets deployed to hosted platforms.

What else, what are other _easy_ solutions we could have?


-- 
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/c970549f-4eb5-44fb-ae6a-e295d393c724%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Re: how to download json data in excel (.xlsx) format without using express.

2016-03-04 Thread Zlatko

On Thursday, March 3, 2016 at 7:11:14 AM UTC+1, Ajay Kumar Jaiswal wrote:
>
>
>
>
>>> The recored set contains millions of record so if i convert it using npm 
>>> json2xls it makes busy the browser and server to converting json into  xlsx 
>>> .so this approach i don't want to use.
>>>
>>
> Even i convert it using "\t" and "\n". it blocks the other process . how 
> to resolve it. i am dealing with large data set. 
>


You could stream your response to the client. It will involve several 
stages in your stream pipeline.
Client opens the request, so you then:
- get the connection
- get the result stream, preferably something in object mode that gives you 
row by row
- pipe it to a stream that will convert result set row into a CSV table row 
(or excel, not sure if you can make that work as a stream though).
- pipe that stream to response.

Then your stream is nice and non-blocking. It's still CPU hungry and lasts 
long, but it doesn't block the server completely, so you can serve multiple 
clients in the same time.

Alternatively, spawn another process that will run your conversion (like 
json2xls). So your server takes a request, and if there is available 
capacity, spawns a process to handle this conversion, returning you a tmp 
file location or something of the sort. Then your server will still work 
for the other, regular requests because this processing is essentially off 
your main process.

Or do something like a two-step process - take the request and put it on 
your job queue - then tell the client "ok, I'll inform you when it's 
ready". Then this job queue is on a separate node or similar process, and 
it informs the client when the xls is ready ;)

-- 
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/380f623a-3675-455b-ae71-cc3de4c8f5a7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Re: Finding: Syntax error unexpected end of file

2016-01-31 Thread Zlatko
In addition to other suggestions of finding this particular bug, you might 
also look into including sourcemaps when transpiling your ts code, for dev 
environment at least. It might help out with these kinds of issues.



On Monday, January 25, 2016 at 8:48:08 AM UTC+1, Theodor Esenwein wrote:
>
> Hi there
>
> Can anyone help me to find a error. One of my NodeJS 5.5 / expressJS 
> application quits with the error: "syntax error unexpected end of file"
> Unfortunately it gives no line at all. Any idea how to hunt and find the 
> location of this error?
>
> The hole project is in Typescript and compiles just fine...
>
> 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/55ace806-7393-4859-b44d-655ace9893d8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Re: How do I use NPM for JavaScript packages?

2016-01-31 Thread Zlatko
Of course you can use npm to download general JavaScript packages, and you 
can use them in the browser, if nothing, then manually.

The simplest use case: 

npm install griddle-react --save

That installs the pacakge in node_modules/griddle-react folder.

>From there you can simply include the script in your HTML:


[nodejs] Re: File Access Permissions and Security of Node.js apps on Linux

2016-01-04 Thread Zlatko
Well, it should be no different then with other runtimes, like Rails or 
maybe a PHP app.

`node` is a binary file, and when you run it, you run it as a certain user. 
This user can access some files on the system, and is blocked to others. 
Likewise, other users can access certain files owned by this user, or can 
be blocked from others. Typical program like any other.

If you want to isolate a Node app on a, say, typical linux system, you 
would run the Node runtime with a separate user, created just for the app. 
You would protect it's home directory (or wherever the app is served from) 
so that only that user (and possibly autodeployment etc scripts) can access 
it. If you want to protect other places on the system, do not let your app 
user (or node user) access to that folder.

But those are simple use cases. Seemingly more complex solution would be if 
you "dockerize" your app - put it in the docker container. The app is then, 
well, contained. Permissions are much more restrictive, depending on your 
setup. And you get other benefits - streamlining deployments, testing etc.

The best part of dockerizing a node app is that it's super simple. You 
learn it in one afternoon, you practice maybe a week and you are good - new 
skill acquired, new levels of complexity that actually simplifies stuff for 
you reached, new options open. And it's applicable to more then just node, 
you can then dockerize other stuff too - database/cashing systems, file 
systems, nginx and whatnot.

Take a look at one of the tutorials available online and see how it goes.


On Sunday, January 3, 2016 at 11:53:43 PM UTC+1, AaronNGray wrote:
>
> Hi, 
>
> A friend asked me a question I was very embarrassed not to be able to 
> answer. Basically he could not find any information on both deploying 
> Node.js app in regard to setting file permissions and on protecting 
> the filing system from Node.js applications. There seems to be no 
> guides to these matters. 
>
> So I would be interested if there is anything available regarding these 
> matters. 
>
> 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/8ff133ad-555f-49f8-ae02-7959f486a605%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Trying to build a MUD that allows Telnet and Web socket connections

2015-12-18 Thread Zlatko
Since it's a different protocol, your socket.io would listen on another port.

So, I guess the game api itself is on abstract enough to be accepting player 
input and sending output in a common way, your connections protocols have to 
hook into this abstract API.

Now, socket connections and telnet ones should all be wrapped into object 
streams, I think (and I think socket.io basically is like an object stream).

That way on ticks your game engine doesn't care where it sends stuff data. And 
it doesn't care how the data comes in as it's always passed to the game engine 
in the same way.

And your both com protocols don't care what the data is, they just need to know 
they're wrapping client side into object stream and converting server data back 
into whatever is needed.

That way you can later add other protocols as well, like pure http (POST for 
input, sse endpoint for output or so).

I'm very curious how it turned out for you - is your project available online?

Former addict 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/b1a0261f-5a8a-4475-88fd-03f1df723080%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Re: need tutorial for nodejs+webrtc

2015-12-02 Thread Zlatko
Not a tutorial, but an actual project, it has some pretty neat usage 
examples:

https://github.com/mafintosh/webrtc-swarm

On Tuesday, December 1, 2015 at 8:38:09 PM UTC+1, Vighnesh Bheed wrote:
>
> Hello..
> Ive been wondering is there good tutorials out there for webrtc and 
> node.js>??. i would like to add marker detection and projection of 3d model 
>  in the SERVERSIDE itself and send the overall result as a video file to 
> the client ? any good tutorial for any of the parts?.
>

-- 
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/181fcac3-2e41-409c-91cc-4e3306557752%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Sharing common endpoints between apps

2015-12-02 Thread Zlatko
I need to share an identical endpoint on two REST API servers in node.

Let's call it `/items`. It's a CRUD-like endpoint, a bit extended with our 
specifics. We also inline apiDoc comments into our routers there so that 
the client devs can also reuse this.

What are some good patterns to keeping those two APIs with their endpoint 
in sync? Currently for us it's a copy-paste job, so naturally it comes out 
of sync on occasion. Due to access restrictions, various consumers can only 
access one or the other.

I was considering two options, and I want a little help.

Shared module version

I'm thinking about a shared repository, but I'm not certain what is a good 
approach there. We have some common, shared endpoints which our various 
APIs and services require, such as data model abstractions, logging, 
utility, but this doesn't exactly fit into one of these.

What would I export from such a module? A self-contained, mountable express 
path would be cool, like:

import { itemsEndpoint } from 'the-shared-repository';
app.use('/items', itemsEndpoint({ dbStuff,  utils }));

To me it sounds relatively decent, but could be the downsides? Besides 
having to find a way to keep apiDoc in sync.

Gateway version

Another idea I'm considering is to actually do build a standalone server 
(http, MQ-based, whatever, we're fully into "microservices"), and then use 
my two REST APIs only as pass-through gateways.

Again, I'd also need a way to share apiDoc documentation too here.

I know it's partially opinion-based, but which seems more right or less 
wrong or easier to maintain? I think in the future I might move more of our 
stuff to similar architecture, so I want to get opinion of this esteemed 
forum :D instead of basing the decission my humble, limited thoughts.

-- 
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/3e32acb8-afd8-471d-843f-f1e49ed8b800%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Re: Creating different arrays with differents elements from one array

2015-11-26 Thread Zlatko
Is all this information in MongoDB? Do you know about mapReduce? mapReduce 
would be your friend there.

Even if all this information is in-memory, a similar map-reduce approach 
could be done.

In essence:
- map phase - for all items, emit the entry in the above format (even with 
empty values where you don't have anything)
- reduce phase - take the items that have the same key ({rid: {id: '123'}} 
I guess in your case) - and merge the items arrays.

Except, you want two different layers - so you need two map-reduce runs, 
and map should be chained onto a filter (that makes sure you have either 
form or format).

Zlatko

On Thursday, November 26, 2015 at 2:48:41 AM UTC+1, Diego Mayorga wrote:
>
> Hi all, i'm trying to do this, I have an array that looks like this:
>
> [ { rId: { id: '123455667' },
> form: 'layer',
> timeStamp: '2015-11-20T10:28:26-03:00',
> exa: '32144B5A2001' },
>   { rId: { id: '123455667'},
> form: 'item',
> timeStamp: '2015-11-20T10:28:28-03:00',
> exa: '30142F13F0138D57' },
>   { rId: { id: '123455667' },
> format: 'item',
> timeStamp: '2015-11-20T10:28:27-03:00',
> exa: '30142F13F0138D54' },
>   { rId: { id: '123455667' },
> format: 'layer',
> timeStamp: '2015-11-20T10:29:09-03:00',
> exa: '32144B5A21AB' },
>   { rId: { id: '123455667' },
> form: 'item',
> timeStamp: '2015-11-20T10:30:19-03:00',
> exa: '30142F13F0138D55' } ]
>
> And I want to create to separete arrayas that look likes:
>
> [ { rId: { id: '123455667' },
> form: 'layer',
> timeStamp: '2015-11-20T10:28:26-03:00',
> exa: '32144B5A2001' },
> items: [
> { rId: { id: '123455667'},
>   form: 'item',
>   timeStamp: '2015-11-20T10:28:28-03:00',
>   exa: '30142F13F0138D57' },
>   { rId: { id: '123455667' },
> format: 'item',
> timeStamp: '2015-11-20T10:28:27-03:00',
> exa: '30142F13F0138D54' }
> ]
> ]
>  [ { rId: { id: '123455667' },
>  format: 'layer',
>  timeStamp: '2015-11-20T10:29:09-03:00',
>  exa: '32144B5A21AB' },
>  items: [
>  { rId: { id: '123455667' },
>form: 'item',
>timeStamp: '2015-11-20T10:30:19-03:00',
>   exa: '30142F13F0138D55' } 
>  ]
> ]
>
> So in simple words, if there are two elements with format layer add 
> elements with format item to the first element with format layer and those 
> who are after the second layer to the second layer, and in the event that 
> there is only one layer add all items formatted items to that layer
>
> This may be silly but do not know where to start.
>
> Thanks.
>

-- 
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/0fafc6a4-d48a-4699-bfbe-715a5e3f4228%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] cache-control mechanism for yeoman (angular+node) application.

2015-11-19 Thread Zlatko
There are a few ways to do that, but I find adding gulp-rev build step the 
easiest to think about.

It's a build step, meaning it's done before you commit your changes and it 
gives you a hash of the file content. So if you change even a single character, 
you have a new hash for that file.

So how does that help? Well, include the hash on the filename, maybe just as a 
query string, for that resource.

E.g. You have file1.js, with hash asdf123, you include that file as 
src="file1-asdf123.js", or "file1.js?rev=asdf123". Now, the client will cache 
that for r. And if you change the file, it has a new hash, and therefore a new 
name, so the browser will fetch it again fresh.

There are other solutions similar to that, like using the file timestamp, gut 
hash num, manually bumping the number etc, but the mechanism is essentially the 
same. If bleeding edge is fine by you, you can also take a look at service 
workers, it's in all the headlines lately, but implemented in only a fraction 
of browsers. Similar to that, there are other ways to do this, but I don't 
think they're worth mentioning here or I don't know enough about them to 
comment.

As said, gulp-rev was always good enough for me.

-- 
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/70bfe330-8b98-425c-a026-3e79d1519dcf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Re: As someone new to Node, should I use Babel or plain ES6 in Node v5?

2015-11-05 Thread Zlatko
This depends a little on what you plan to do with your node-fu.

If you plan to learn a bit more, maybe work on your personal projects or 
start something new in a new company, then I think you should just start 
with Node 4 (the TLS version) and write "native" ES6. Even if you're just 
learning at the moment, you can still go on and learn, because most of the 
time the transpiler is set up only once, at the project start, and then you 
forget about it.

And if you plan to contribute to older codebases etc, you can just add the 
transpile step later, and you're done.

But if you plan to go work in a company already using node, or publishing 
libraries that you expect will be widely used, be aware that a lot of 
companies still use Node 0.10 and Node 0.12, and those apps will be around 
for a long time. So working on something like that might even mandate the 
use of ES5 only, without even transpilation.

So TL;DR would be, just write ES6, worry about transpilation when you have 
to.




On Wednesday, November 4, 2015 at 8:22:25 PM UTC+1, Willem Odendaal wrote:
>
> Node seems to be evolving rapidly, and I wonder what the community 
> sentiment is around using transpilers at the moment.
>
> As someone just starting out, is it a good idea to use a transpiler like 
> Babel to get most ES6 features? Or is the community moving towards using 
> the ES6 features supported in Node v5?
>
> Just trying to get an idea of the preferred practice at the moment, before 
> I head off in the wrong direction.
>
> Thanks.
>

-- 
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/592960f8-4cab-4f85-815b-29584d66faa7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Re: Calculate statistics

2015-11-03 Thread Zlatko
That is really a too wide question.

The general answer is that you can (of course) use both. But which one is 
better?

It depends on so many things, your use cases, your current codebase, where 
is all the data being held, what kind of business inteligence and what kind 
of statistical information you're into. You'd have to get into much more 
detail to make a good choice. Perhaps you can even hire an independant 
consultant who can go with you and analyze your requirements and build a 
pros and cons for both choices and help you decide.

In any case, the question is really wide just set like that.


On Tuesday, November 3, 2015 at 1:11:42 AM UTC+1, Diego Mayorga wrote:
>
> Hi, i'm working with two databases, mongodb and influxdb, and I want to 
> generate statistical information for bussines inteligence. My question is 
> which of the two best supports statistical calculations?
>

-- 
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/5200b107-b5a4-49b0-a179-35cec78dd783%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Re: what are the merits / demerits of require.extensions?

2015-10-12 Thread Zlatko

On Sunday, October 11, 2015 at 6:37:16 AM UTC+2, Brian Takita wrote:
>
> Deprecating `require.extensions` is unfriendly to developers who want to 
> require a template file.
>
> No, I don't want to have to add more layers of complexity to my build 
> process, thank you. I just want to use *custom* logic for my app/platform. 
> I don't have other users, it's my sandbox, thank you. Please don't tell me 
> what's good for me, I know what's good for me, thank you!
>
>>
>>

 Now, that sounds exclusivist, too. I could say something like "you don't 
want to introduce complexity to your build process? Well me too, I prefer 
to keep your .coffee (or whatever) bugs out of mine."

But that is not constructive, so I'll proceed with an example.

I write ES6 code, the whole team does here. I even write my tests in ES6. 
And we don't see the .js files, either. We have transpilers as part of our 
build and test process, and I don't see any obstacle with that.

You do something like style checkers, linters, documentation compilers when 
you develop, right? Maybe a small browser syncing server, if you're full 
stack? Putting a transpiler step in one of those steps is a trivial thing 
to do. You do it already, anyway, so another step or two, another few 
milliseconds should not matter.

Yeah, yeah, I know people are saying they only use it for development, 
right? Just like people only don't write tests for development, right? Only 
tested modules get published to npm. I know there would be gains for people 
writing in other languages then JavaScript by having a full support of 
require.extensions. But there are also clear advantages of not doing it. 
The main thing - Node.js core will remain much more stable and with less 
bugs in the system overall.

You know of JRuby, Jython and other languages that run on JVM? I would take 
a hint there. I think that if this is really a useful feature, sooner or 
later a native module or addon or similar will appear that will resolve 
this. So, the core remains clean, the addon is clear in what it does, and 
everything works as intended. That's how I would like this to play out.

Though, I'm not the core maintainer, not even a contributor, so my 
complains and wishes wouldn't count anywhere as it is, would they?

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/bdbf1a1a-dfbf-4d2b-9099-724cecc1f362%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Re: State of ES6/ES7 in node/v8?

2015-10-05 Thread Zlatko
You can write full ES6 apps and transpile with babel.js. It's very feature 
complete, even has stage 1 and stage 0 features (ES7 and onward). It will 
also provide you with a polyfil, so it will add features that you miss as a 
polyfil.

As for performance, this chart is a little old, but gives a good overview 
anyway:

http://www.incaseofstairs.com/2015/06/es6-feature-performance/

As for what's implemented, what isn't, here's another link which a lot of 
community deems relevant:

https://kangax.github.io/compat-table/es6/

It depends also on which Node version you use, too. Example, 4.0 has a lot 
more of ES6 then 0.12, and 0.12 has  lot more (well, has vs has not) 
compared to 0.10. (You should migrate to at least 0.12 anyway if you're 
using anything older.
So for those, implemented features, they should usually (not always) 
perform better then babel polyfil.


On Sunday, October 4, 2015 at 4:31:08 AM UTC+2, Sathish Kumar wrote:
>
> Ref:https://github.com/nodejs/node/issues/3164#issuecomment-145199629 
>
> I know this is not node question.. But want to know what community 
> thinks.. 
>
> Can I write a full application using current es6 features released with 
> node? 
>
> Can I combine write es5 and es6. Will it lead to performance issues? Ex 
> current node/v8 does not have es6 import/export. I can write a class but 
> use module.exports to export. Does it affect anywhere? 
>
> If anyone did how was the performance? 
>
> I see some of them say native promises are slower, and performance of 
> let===var.. Does this affect a web application? Is there any issues raised 
> in v8 regarding this? 
>
> ES7- 
>
> Many of us know Microsoft has added the experimental async and await 
> feature in chakra.. 
> That is awesome right?.. It will add some cleaner async operations.. Now 
> that feature is added to stage 2 and may added stage 3 in near future.. 
> Does anyone know when v8 gonna adds this and node gonna adapt? Timeline? 
>
> P.S: if this is not right place to ask this question.. Point me where I 
> need to move. 
>
> Thanks

-- 
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/fd0f371b-ecfc-42f6-bf9d-b35d809fe3ec%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Re: Asynchroneous answer to the client with nodejs and socket.io... is it possible?

2015-09-27 Thread Zlatko
Yes, it is, it's quite easy, if your socket connection persists (or your 
server and client have means to reconnect if the socket is short-lived).

Example would be something like this:

```
io.on('connection', function(socket){

  socket.on('message', function(msg) {


  })
});
```

On Friday, September 25, 2015 at 9:16:09 PM UTC+2, Bouch Seb wrote:
>
> Hi, thanks for reading my newbie question. Sorry if it's already in the 
> forum and I didn't find it...
> Is it possible to have this sequence with nodejs through socket.io:
> 1. a client requests the server
> 2. the server answers and runs a setTimeout function
> 3. when the setTimeout elapses, the server sends another answer to the 
> client
> Easy?
> Thanks in advance for your answer.
>

-- 
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/977c4a4a-2eef-4c8f-99c4-6091e92ceaca%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [nodejs] Possible to select globally installed module over locally install one?

2015-09-13 Thread Zlatko
What do you mean, they're not requireable?

[zlatko@zlatko-mint /tmp]$ node -e "require('express')"
module.js:338
throw err;
  ^
Error: Cannot find module 'express'
[...cut...]

    [zlatko@zlatko-mint /tmp]$ npm i -G express
\
[...cut...]

    [zlatko@zlatko-mint /tmp]$ node -e "require('express')"
[zlatko@zlatko-mint /tmp]$ 


For the OP, it's possible to do it manually, ie: `
require('/home/zlatko/.nvm/versions/node/v4.0.0/lib/node_modules/gulp');` 
but it's not very scalable.

The problem is - when I bump my node version to, say, 4.0.1, I'd have to 
fix the path. Also, if it were you, you would not have a `/home/zlatko` 
part, but possibly /usr/lib/node_modules or similar.


I don't know if there's a node config option for something like that 
though, probably there isn't.

Zlatko

On Sunday, September 13, 2015 at 12:55:56 AM UTC+2, Sam Roberts wrote:
>
> On Thu, Sep 10, 2015 at 2:51 PM, Bgsosh <bgs...@gmail.com > 
> wrote: 
> > When there is both a globally locally installed version of a module, 
> does 
> > anyone know if it is possible to require() the global version, over the 
> > local one? 
>
> Global modules are misnamed, they are only scripts that you intend to 
> run, they are NEVER requireable. 
>

-- 
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/3dfa3049-a3f1-4903-8ee7-bd49b4333cb5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [nodejs] Node/Express best practice regarding multiple apps on 1 instance

2015-09-09 Thread Zlatko
You're asking for best practices: nginx is it. Put nginx in front, and it will 
even be faster and better then node at ssl stuff, so your app only listens on 
one port.

It is trivial to install, and it is simple to configure, read a little about 
node and nginx and multiple apps. 
DigitalOcean 1GB droplet it's perfectly capable of housing nginx, a few small 
node apps, and maybe a small database, though it varies, depends on usage.

As for terminals, either look into forever or pm2 modules oh npm. They each 
have good docs on how to do the setup 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/d6794ab2-6fa1-42e7-8cf9-4a608a76c28b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Re: raspberry pi 2 B+ and node.js -- a drift and need a life perserver

2015-08-19 Thread Zlatko
Your code doesn't seem correct (nevermind the syntax errors). You also 
didn't post any potential results.

These kinds of questions would be better off at stackoverflow.com, but here 
are a few pointers.

The thing to realize here is that gpio.read and gpio.write are async 
functions, and your first call gpio.read(doorclosed, gpio.DIR_IN, 
readInput); seems synchronous, so our check (if (doorclosed === true){} ) will 
always fail.

You also seem to have too many params (according to documentation 
at https://www.npmjs.com/package/rpi-gpio) at further gpio.read calls, you 
only need PIN number and callback. The second thing is that your second 
check (whether the door is closed) should most likely be polling, say, 
every second or so, because this way it'll make a check right away after 
starting the doorOpen, and it'll probably be too fast..

An example of a raiseDoor function would be as:

function raiseDoor() {

  // first check that the door is closed.
  // the callback we pass in is a function which will receive (err, value) 
arguments - err if there was a problem during this call, value if not.
  gpio.read(DOORCLOSED, doorClosedCallback);
}

Two things - I wrote the doorclosed in CAPS, to signal the developer (be it 
yourself or somebody else) that the this variable is constant, we don't 
plan to change it. I suggest doing this for gpio-pin numbers for code 
clarity.
Second thing, now we need to write this doorClosedCallback. It will be 
called when that gpio.read above reads the sensor value.

function doorClosedCallback (err, value) {
  // check for errors
  if (err) {
  console.log('Error checking if the door was open', err);
  return;
  }
  // if no errors, we can see the door position.
  if (value === true) {
// door is open, skip.
console.log('Door open, ending.');
return;
  } else {
// door is not open. We need to do two things:
// 1. kick off the door motor (write to 'opendoor' PIN)
// 2. start polling - check every second if the door is now closed, and 
when it is, stop the door motor.
gpio.write(OPENDOOR, true, doorInMotion);
  }
} 

As you can see, I'm writing true, and again offloading this check of the 
work complete to another function - that way it's easier to reason about 
those simple functions with simplified jobs.

So let's write it:

function doorInMotion (err) {
  // it will only receive an error if our gpio.write(OPENDOOR) failed - 
meaning, if we failed to start the door motor.
  if (err) {
console.log('Door start failed.', err);
return;
  }
  // now is the trick. We want to check every second if the door is open. 
If yes, write a zero to opendoor pin, so that we stop the engine.
  // we do this every second, and we save this interval.

  var interval = setInterval(function() { // this inner function runs every 
second, until somebody calls the interval.cancel();

// every second, check the door sensor.
gpio.read(DOOROPEN, function(err, value) {
  if (err) {
console.log('Error reading door-open value.', err);
return; // also could be a good idea to stop the engine here, 
because due to error, we don't know if the door is open or not, maybe 
sensor has failed.
  }
  // anyway, if the sensor didn't fail, we can check the DOOROPEN pin 
value:
  if (value !== true) {
console.log('Door not yet open, keep the motor running.');
  } else {
console.log('Door is finally open.');
// now stop the door
gpio.write(OPENDOOR, false, function(err) {
   if (err) {console.log('Error stopping the door motor.', err);
});
  } 
});
  }, 1000);
}


This is just one, basic solution example, it can probably be made better 
and simpler. But I think it should at least get you started.


On Tuesday, August 18, 2015 at 5:49:40 PM UTC+2, jps birdzbeez wrote:

 I am not a programmer and never claimed to be one.. I just read and read 
 and read.. trying to learn and understand.. but for some reason I am not 
 sure I am understanding how this works...  if someone doesn't mind I need 
 help to point me in the correct direction to get my project going.. What I 
 am able to do is make it work in python but I like the idea of node.js over 
 python..  


 The project is to use my raspberry pi to raise or lower a door (not a 
 garage door). At the top and bottom are Hall Effect sensors. Before raising 
 the door I want to verify the door is closed. If it is closed then raise 
 the door till it reaches the opendoor state. I have not had any luck with 
 node.js programming..  this is what I have come up with so far.. 

 var gpio = require('rpi-gpio');
 var doorclosed = 31; //hall effect sensor when door is closed
 var dooropen = 33; //hall effect sensor when door is open
 var opendoor = 35; //cause door to open
 var closedoor = 37; //cause door to close


 function raisedoor(callback) {
   //verifydoorclosed(function verified door closed on gpio 31)
   gpio.read(doorclosed, 

[nodejs] Re: raspberry pi 2 B+ and node.js -- a drift and need a life perserver

2015-08-19 Thread Zlatko
Forgot the interval.cancel():

On Wednesday, August 19, 2015 at 11:28:41 PM UTC+2, Zlatko wrote:


 So let's write it:

 function doorInMotion (err) {
   // now is the trick. We want to check every second if the door is open. 
 If yes, write a zero to opendoor pin, so that we stop the engine.
   // we do this every second, and we save this interval.

   var interval = setInterval(function() { // this inner function runs 
 every second, until somebody calls the interval.cancel();

 // every second, check the door sensor.
 gpio.read(DOOROPEN, function(err, value) {
   if (err) {
 console.log('Error reading door-open value.', err);
 return; // also could be a good idea to stop the engine here, 
 because due to error, we don't know if the door is open or not, maybe 
 sensor has failed.
   }
   // anyway, if the sensor didn't fail, we can check the DOOROPEN pin 
 value:
   if (value !== true) {
 console.log('Door not yet open, keep the motor running.');
   } else {
 console.log('Door is finally open.');
 // now stop the door


And stop the interval here too: clearInterval(interval);
 

 gpio.write(OPENDOOR, false, function(err) {
if (err) {console.log('Error stopping the door motor.', err);
 });
   } 
 });
   }, 1000);
 }



 

-- 
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/da75c2ac-7915-47ed-a09e-09539f92954b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [nodejs] Re: Losing scope of variable

2015-03-20 Thread Zlatko Đurić
Off-topic first:
Didn't know Aria was a moderator here (although I read a lot of your
posts), and I thank you heartily for your effort. You're doing a great job.

At the OP:

In all test frameworks there's an usual way of setting up and dismantling
test suites. I'm not sure what you use there, but there should be something
like `before()` and `after()` for that where you'd setup the page and make
it accessible in the test suites' scopes.


2015-03-20 18:42 GMT+01:00 Aria Stewart aredri...@dinhe.net:


  On Mar 20, 2015, at 11:58 AM, CoffeeManiac dschin...@gmail.com wrote:
 
  It's very very very very annoying that these posts are moderated.  What
 forum does that!

 Ones where people post job ads all the time, where people double-post when
 things are vaguely slow, and ones where people bring dead threads back from
 the grave about something tangentially related, when they should start a
 new thread instead!

 Also ones where we expect a minimum standard of kindness and decency and
 intend to enforce that.

 Sorry I've been slow approving messages -- I suspect we're on opposite
 ends of the world!

 Aria

 --
 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 a topic in the
 Google Groups nodejs group.
 To unsubscribe from this topic, visit
 https://groups.google.com/d/topic/nodejs/QRX6t4c3ViY/unsubscribe.
 To unsubscribe from this group and all its topics, 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/7972C72E-4E20-4AA0-B306-7EB4BD2CA915%40dinhe.net
 .
 For more options, visit https://groups.google.com/d/optout.




-- 
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/CADu3pbzAN8MmFCLGtiidofV0%2BhNudD-VkSebCXPV89ykOEVB_A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


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

2015-03-03 Thread Zlatko Đurić
 was hoping the
 composed object would be able to look at its parent environment for
 shared common information between them so that I didn't have to init it
 or redefine it at the lower levels.

 --
 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 a topic in the
 Google Groups nodejs group.
 To unsubscribe from this topic, visit
 https://groups.google.com/d/topic/nodejs/cyVYXFGfAr0/unsubscribe.
 To unsubscribe from this group and all its topics, 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/9ba3e6c4-c8d7-4efa-af09-7b05be637fe7%40googlegroups.com
 https://groups.google.com/d/msgid/nodejs/9ba3e6c4-c8d7-4efa-af09-7b05be637fe7%40googlegroups.com?utm_medium=emailutm_source=footer
 .

 For more options, visit https://groups.google.com/d/optout.




-- 
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/CADu3pbwCD6DUzca0Zum4Uz7TD%3DKs_HvXXRjJ_Xkzg_AnM277kw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [nodejs] Re: Support plugin system in Node.js

2015-02-03 Thread Zlatko Đurić
Yes, that's what I was talking about. That's the closest thing to
plugin-like architecture that I can think of. I'm pretty sure that there
are others, though.

For example, sails.js is a framework with lots of stuff out of the box, but
also has adapters and stuff for different purposes. But I think mean.io has
more complete 'package' system for plugins.

I personally like to work on bare express, as I always tend to customize
heavily - and mean.io and others are excellent as long as you stick to the
pattern.

So if you plan to deploy lots of simpler features, that may be the way to
go. If you want to customize a lot, to optimize, to make the app perfect
for your use case, I would go with something a bit less magic and more
extendable.


2015-02-03 19:24 GMT+01:00 Shao Tian tyrell...@gmail.com:

 Thanks very much!
 Are you referring to the package concept of mean.io?



 On Monday, February 2, 2015 at 10:49:58 PM UTC-8, zladuric wrote:

 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 a topic in the
 Google Groups nodejs group.
 To unsubscribe from this topic, visit
 https://groups.google.com/d/topic/nodejs/nnDSRJFSJt0/unsubscribe.
 To unsubscribe from this group and all its topics, 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/6353ed40-5a95-4122-9dac-d825239ca465%40googlegroups.com
 https://groups.google.com/d/msgid/nodejs/6353ed40-5a95-4122-9dac-d825239ca465%40googlegroups.com?utm_medium=emailutm_source=footer
 .

 For more options, visit https://groups.google.com/d/optout.




-- 
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/CADu3pbzK7sQpo7PwsO0CNaDET-p4UA9LZos0osdOgwudeA0Kug%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] A module to empty an S3 bucket

2014-08-12 Thread Zlatko Đurić
I needed to empty an S3 bucket of test data, but I could find nothing out
of the box.

So a bit later you can now:

npm install empty-s3-bucket -g
export S3_ACCESS_KEY=key
export S3_SECRET=secret
export S3_REGION=us-east-1
empty-s3-bucket my-bucket

It's not much or very elegant, but it works for me, so I thought it might
help somebody else.

Constructive criticism welcome.

-- 
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/CADu3pbzzEemEizr1wCsMOX4dm%2BUHxS%2BZjF6F2JMpyQ-U-7UShQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [nodejs] Re: Java Houses Adopting Node.js

2014-07-05 Thread Zlatko Đurić

On 04.07.2014 14:58, Adam Davies wrote:
Seems like the state of the art is to stick with Java services on the 
backend and use Node as a page server to server HTML pages content, so 
that Node is a kind of front-controller or proxy.





In a way. Node can do a lot of work and it can handle a whole lot of 
connections, as well as route all those connections between Java 
services, databases and other stuff.


The thing where it is not the best match is heavy-duty processing. So, 
if you're serving images or have a webshop or something that connects to 
many different warehouses to pull data from, Node is great. If you're 
doing video encoding and recoding, then yep, leave that part to Java.



--
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/53B714D8.4090608%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


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

2014-06-27 Thread Zlatko Đurić
Where can one look for this code, write barriers and stuff? (I guess
curiosity is getting the better out of me, or however the saying goes.)


2014-06-27 13:15 GMT+02:00 Zlatko Đurić zladu...@gmail.com:

 So that means that 'I guess that translates to create as many small
 local scoped vars as you need, and V8 will take care of it all, as long
 as they don't point to global scopes and other stuff?

 Or is this _always_ something that needs to be checked, regardless?


 2014-06-27 7:11 GMT+02:00 Ben Noordhuis i...@bnoordhuis.nl:

 On Thu, Jun 26, 2014 at 12:08 PM, zladuric zladu...@gmail.com wrote:
  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.

 That's not bad advice but there's a caveat.

 The garbage collector in V8 is generational.  It needs to know what
 new space objects contain references to old space objects and in order
 to get that information, stores to properties in new space objects go
 through something called a write barrier[0].

 What that means is that an assignment like `object.x = value` gets
 translated into code that conceptually looks like this:

   // Update write barrier unless value is an int.
   if (IsSmallInteger(value) === false) {
 RecordWrite(object, 'x');
   }
   Store(object, 'x', value);

 (The write barrier is elided when the value is an integer because
 integers are not stored as objects and don't reference other objects.
 Numbers can be heap-allocated but signed integers that fit in ~30[1]
 bits usually are not.)

 You shouldn't let the above worry you too much but in performance
 critical code, it sometimes pay not to mix new and tenured objects.
 (Something node.js core doesn't do too well, alas.  The http and
 stream modules, for example, have lots of backlinks between objects
 with different lifetimes.)

 [0] Not to be confused with a hardware write barrier.
 [1] The exact width depends on the hardware architecture.

 --
 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 a topic in the
 Google Groups nodejs group.
 To unsubscribe from this topic, visit
 https://groups.google.com/d/topic/nodejs/tx6FCaVvf44/unsubscribe.
 To unsubscribe from this group and all its topics, 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/CAHQurc_xmhTG2oQ%2B8%3D0rvNyfqeb5ksrxAhpviEudTAz-bJ3YUA%40mail.gmail.com
 .
 For more options, visit https://groups.google.com/d/optout.




 --
 Zlatko




-- 
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/CADu3pbzQ88%3DUmQ7gGFYTtp2cZj6Atp5A5YYAnzsrVa%2BbyN1tsw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [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 Zlatko Đurić
For what is worth, I never did the slicing and I'm working as a Node.js dev
at least partially for the last year or so.


2014-03-05 16:09 GMT+01:00 gitted sahmed1...@gmail.com:

 Thanks for the perspectives.

 I'm fine with front end, but what I mean is I don't slice photoshop psds
 and take psds = html/css.  I can work in the environment, but not into
 doing it from scratch like a pure designer/html coder would do.


 On Wednesday, March 5, 2014 5:15:15 AM UTC-5, zladuric wrote:

 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 a topic in the
 Google Groups nodejs group.
 To unsubscribe from this topic, visit
 https://groups.google.com/d/topic/nodejs/nH5_BpZCUZs/unsubscribe.
 To unsubscribe from this group and all its topics, send an email to
 nodejs+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.




-- 
Zlatko

-- 
-- 
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] Re: Print form node

2014-02-10 Thread Zlatko Đurić

On 02/10/2014 02:00 PM, Lincoln Lemos wrote:
Yes, I want click on 'print' button and this send a job to a user's 
printer. (With no dialogs).
Maybe i can make a function to click Print Automatically, and send 
the jobs with no actions.




Uh, then tough luck! I don't think this is possible with any server-side 
code, at least not in the regular sense.


I think the most that you can do here is autostart a print dialog. That 
means doing something like window.print(); or iframeElement.print(); in 
frontend javascript. But it's not related to node. Also, the above will 
not automatically print, it will just open the users' print dialog - if 
they have any installed.


The problem is generally in that that the browser scripts cannot access 
hardware, and probably the browser itself can't access it by default.


It could possibly be done with some sort of browser extension, but I'm 
not sure about this.


In any case, it is nothing to do with node.js. Your server will probably 
have no access to the printer ports if it is not in a sort of a vpn or 
local network and having remote admin access to the users' computer. 
Which is probably not the case :)







2014-02-06 7:26 GMT-02:00 zladuric zladu...@gmail.com 
mailto:zladu...@gmail.com:


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 tel:62%2081998667
*

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




--
Lincoln Lemos
*62 81998667

*BIGO Design http://bigodesign.com.br

--
--
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 a topic in the 
Google Groups nodejs group.
To unsubscribe from this topic, visit 
https://groups.google.com/d/topic/nodejs/mV2DZWFjn2c/unsubscribe.
To unsubscribe from this group and all its topics, send an email to 
nodejs+unsubscr...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.



--
Zlatko

--
--
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 Zlatko Đurić
, send an email to
 nodejs+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.




-- 
Zlatko

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