需要在节点中使用jQuery

我有一个节点,在窗口上的mongodb设置,并在开发一个Web应用程序。 在server.js文件中,我有一个类似这样的post路线:

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); }); }); 

这是行不通的,因为$(param)不会在没有npming jquery的节点上运行。 问题是在windows上安装jquery包的节点没有正确安装。 有没有其他的方法? 我需要以一种干净的方式从该对象中构build一个查询string。

构build查询string有更简单的方法。 你真的不应该为它安装jQuery,如果这是你想要做的,即使你可以。 尝试querystring npm包。

如果你必须在节点中使用jquery,那么看看cheerio 。 它是专门为服务器devise的核心jQuery的一个小巧,快速和优雅的实现。