Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

AJAX Helper for NodeJS, instead of jQuery?

AJAX Helper for NodeJS, instead of jQuery?

Problem

I just want to do something like $.get/post on a server side script. Is there a better way instead of including the whole jQuery? I prefer not to use the messy get xml http requests stuff manually either.

Problem courtesy of: Jiew Meng

Solution

The equivalent to jquery.ajax in node.js is request

It sits on top of the node core http and makes things nicer to work with. Allowing for both callback and streaming requests.

examples:

var request = require('request');
request('http://www.google.com', function (error, response, body) {
  if (!error && response.statusCode == 200) {
    console.log(body) // Print the google web page.
  }
})

request.get('http://google.com/img.png').pipe(request.put('http://mysite.com/img.png'))
Solution courtesy of: generalhenry

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

AJAX Helper for NodeJS, instead of jQuery?

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×