[nodejs] Re: How to handle invalid JSON in http.request?

2015-10-05 Thread Jimb Esser
Looks like the problem is the "json" middleware, presumably (in the code 
above what you pasted), you're adding that to your express app?  The json 
middleware will not work with requests saying they're application/json and 
not passing data in the same format as the middleware expects.  Try not 
using that, or using it only for routes that actually need it?

I'm not at all familiar with recent versions of Express, so it's possible 
that's getting added in automatically somehow, but I'd guess you're opting 
in to it somewhere.

Also, you may be interested in node-http-proxy 
, it is very robust at proxying 
anything Node can deal with.

Hope this helps!
  Jimb Esser

On Saturday, October 3, 2015 at 7:30:57 PM UTC-7, Nigel Brown wrote:
>
> Using nodejs and express I am trying to write a proxy of sorts, to handle 
> a set of mapped urls in different back end servers. The code is below. It 
> seems to work pretty well. 
>
> Unfortunately, I have a naughty client, that says it is sending 
> application/json whereas it actually sends two json objects on different 
> lines.
> {...}
> {...}
>
> So, when I receive this I get the following error:
>
> SyntaxError: Unexpected token {
>
>  at Object.parse (native)
>
>  at /Users/nigel/code/webui/nodejs-api/node_modules/express/node_modules/
> connect/lib/middleware/json.js:75:25
>
>  at IncomingMessage.onEnd (/Users/nigel/code/webui/nodejs-api/node_modules
> /express/node_modules/connect/node_modules/raw-body/index.js:109:7)
>
>  at IncomingMessage.g (events.js:199:16)
>
>  at IncomingMessage.emit (events.js:104:17)
>
>  at _stream_readable.js:908:16
>
>  at process._tickCallback (node.js:355:11)
>
>
>
> Which is fair enough in some ways. The trouble is, the proxied server is 
> expecting this double JSON, so, my proxy is blocking what the client and 
> server think is valid content. 
>
> So the question is, is there any way I can pass this straight through 
> (without doing the JSON parse) or trap the error and repair it?
>
> I am pretty new to nodejs and express, so this might be obvious to one of 
> you.
>
> Many thanks.
>
>
>   app.all(path,  function(request, response) {
>
>  
>
> var turl = request.url.substring(n); 
>
> var puri = url.parse(target); 
>
> var proxy_request = http.request({port: puri.port, host: puri.hostname
> , method: request.method, path: turl, headers: request.headers}); 
>
> proxy_request.addListener('response', function (proxy_response) { 
>
>   proxy_response.addListener('data', function(chunk) { 
>
> if(this.headers['content-type'].indexOf('json') > 0) { 
>
>   console.log('writing response ' + chunk); 
>
>   response.write(chunk); 
>
> } else { 
>
>   response.write(chunk, 'binary'); 
>
> } 
>
>   }); 
>
>   proxy_response.addListener('end', function() { 
>
> console.log('response end'); 
>
> response.end(); 
>
>   }); 
>
>   response.writeHead(proxy_response.statusCode, proxy_response.headers
> ); 
>
> }); 
>
> request.addListener('data', function(chunk) { 
>
>   if(chunk) { 
>
> console.log('writing to proxy ' + chunk); 
>
> proxy_request.write(chunk, 'binary'); 
>
>   } 
>
> }); 
>
> request.addListener('end', function() { 
>
>   console.log('request end'); 
>
>   proxy_request.end(); 
>
> }); 
>
> if(request._body) { 
>
>   var txt = JSON.stringify(request.body); 
>
>   if(txt =='{"somevalidjson":"yes"}') { 
>
> console.log('bad!!!'); 
>
>   } 
>
>   console.log('writing body ' + txt); 
>
>   proxy_request.write(txt, 'binary'); 
>
>   proxy_request.end(); 
>
> } 
>
>   });
>
>
>

-- 
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/ca728147-8368-4e5d-8838-ab0ecd41a291%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] NPM publish

2015-10-05 Thread jayesh sapkale
1:) How to publish whole project to npm?
2:) How to make our project available globally and generate executable file 
like in window (.cmd) file in \Roaming\npm  folder 

please help 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/25325032-26b6-4d45-8fc7-4edab3d662bc%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: start nodejs express automatically

2015-10-05 Thread Craig Coleman
Thanks for the lines.
ndm wrappers.  I am finally understanding a a bit of this.
 ndm wrappers  *https://github.com/npm/ndm*
*Could you please send me of an example that works.  *
*Thanks*
cwc


On Saturday, August 29, 2015 at 10:33:46 PM UTC-7, Aria Stewart wrote:
>
>
>
> On Friday, August 28, 2015 at 10:41:48 PM UTC-4, Uomo di Carbone wrote:
>>
>> Is there a way to add nodejs express to rc similar to adding vsftp to rc?
>> sudo update-rc.d vsftpd defaults
>>
>> I'm running nodejs with express on port 80 using Debian on an Rpi
>>
>>
> I use ndm wrappers; it's a bit funky but works for me.
>
> More simply, one can tuck things into an @reboot rule in crontab, add them 
> to /etc/rc.local or equivalent, or you can write an init script (or I 
> expect there are several generators for this other than ndm) and use 
> update-rc.d
>
> 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 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/fab71850-552d-45c8-88b1-ffccc5f93211%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Re: NPM publish

2015-10-05 Thread Aria Stewart


On Monday, October 5, 2015 at 9:56:12 AM UTC-4, jayesh sapkale wrote:
>
> 1:) How to publish whole project to npm?
> 2:) How to make our project available globally and generate executable 
> file like in window (.cmd) file in \Roaming\npm  folder 
>
> please help here...
>  
>

To publish: npm publish
To install globally and have an executable: make sure there's a 'bin' entry 
in package.json, publish, then npm install -g yourpackage 

-- 
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/cd727d6b-77dc-42c4-be1e-82494f3c2366%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[nodejs] Re: start nodejs express automatically

2015-10-05 Thread Aria Stewart


On Monday, October 5, 2015 at 9:56:08 AM UTC-4, Craig Coleman wrote:
>
> Thanks for the lines.
> ndm wrappers.  I am finally understanding a a bit of this.
>  ndm wrappers  *https://github.com/npm/ndm *
> *Could you please send me of an example that works.  *
> *Thanks*
> cwc
>

https://github.com/aredridel/bouncy-service is one I 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/def3f853-6b1f-4416-9f6b-7ac89b05cb19%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.