1

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.

7
  • 1
    Including the whole of jQuery is a bit overkill if all you need from it is building the query string. Commented Mar 15, 2013 at 7:13
  • so what do you suggest? Commented Mar 15, 2013 at 7:14
  • 5
    @beNerd You should be able to use require('querystring'), esp. qs.stringify(). Commented Mar 15, 2013 at 7:16
  • Do you even know where jQuery is for? You want to for example fade, animate or change css server side? Commented Mar 15, 2013 at 10:42
  • @Bondye Yes i know what jquery does very well :). Don't be so rude. I just didn't know the querystring package available with npm and so the question. Commented Mar 15, 2013 at 12:03

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.