beNerd
beNerd

Reputation: 3374

need to use jquery in node

I have a node,mongodb setup on windows and in process of developing a webapp. In the server.js file i have a post route like this:

var http=require('http');
app.post("/leadAPI/ed",function(request,response){

var data={firstname:request.body.firstname,lastname:request.body.lastname,email:request.body.email,areaOfInterest:request.body.areaOfInterest,highestEducation:request.body.highestEducation,daytimePhone:request.body.daytimePhone,eveningPhone:request.body.eveningPhone,addressOne:request.body.addressOne,addressTwo:request.body.addressTwo,city:request.body.city,state:request.body.state,zip:request.body.zip,country:request.body.country};

edDoc=new edModel(data);
edDoc.save();

var options={
hostname:'www.someRemoteUrl.com',
port:80,
path:'/some/path/on/that/url?'+$.param(data),
method:'POST'
};

var req=http.request(options,function(res){
console.log(res);
});


});

This doesn't work because $(param) won't run in node without npming the jquery. problem is that installation of jquery package for node on windows doesn't get installed properly. Is there any other way around? I need to build a query string out of that object in a clean way.

Upvotes: 1

Views: 119

Answers (2)

Munim
Munim

Reputation: 6510

There are much easier ways to construct a querystring. You really shouldn't install jQuery for it if that is all you want to do, even if you could. Try the querystring npm package.

Upvotes: 1

user568109
user568109

Reputation: 47993

If you have to use jquery in node, then take look at cheerio. It is a tiny, fast, and elegant implementation of core jQuery designed specifically for the server.

Upvotes: 0

Related Questions