Tag: 表示

构build失败的nodejs sqlserver驱动程序

我正在尝试通过键入以下命令为我的应用程序在node_modules目录中安装node-sqlserver , npm安装node-sqlserver 这是我得到的, npm WARN package.json application-name@0.0.1 No README.md file found! npm WARN package.json node@0.0.0 No README.md file found! npm http GET https://registry.npmjs.org/node-sqlserver npm http 304 https://registry.npmjs.org/node-sqlserver npm WARN deprecated node-sqlserver@0.1.0: This package has been superseded by msnodesql. > node-sqlserver@0.1.0 install C:\Users\Tarun\Desktop\Songify\node_modules\node-sqlserver > node-gyp rebuild C:\Users\Tarun\Desktop\Songify\node_modules\node-sqlserver>node "C:\Program Files (x86)\nodejs\node_modules\npm\bin\node -gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild gyp ERR! rebuild […]

使用Pushstate和NodeJS

我正在使用NodeJS和HTML5 pushstate。 我有我的index.html在“/”与链接去“/ home /”通过pushstate。 所有没关系,但如果我刷新/ home /,我的服务器返回“无法GET / home /”。 我只想“/ home /”返回我的index.html文件,如“/” 我的代码: var express = require("express"), app = express(); app.use(express.static(__dirname + '/public')); app.get('/home/', function(req, res, next) { //what to do here? }); app.listen(3001); 谢谢。

填充后错误的数组顺序

我有这个问题,但是我不能在这里粘贴整个代码,所以让我试着解释一下。 我需要通过idfind一些文件,并填充它的ObjectId的数组元素。 比方说,我有从用户集合中的以下文件: { _id: 1, "first_name":"Nick", "last_name":"Parsons", "email":"nick@movementstrategy.com", "password":"foo", "clients":[ "50f5e901545cf990c500000f", "50f5e90b545cf990c5000010", "50f5e90b545cf990c5000013" ] } find它后,我就像这样填充它的客户: User.findById(1) .populate('clients') .exec(function (err, user) { }); 上面的代码执行后,我有'用户'variables与客户端的填充数组。 但客户有错误的顺序,像这样: { _id: "50f5e901545cf990c500000f", "first_name":"cl1", }, { _id: "50f5e90b545cf990c5000013", "first_name":"cl3", }, { _id: "50f5e90b545cf990c5000010", "first_name":"cl2", } 应该: "50f5e901545cf990c500000f", "50f5e90b545cf990c5000010", "50f5e90b545cf990c5000013" 代替: "50f5e901545cf990c500000f", "50f5e90b545cf990c5000013", "50f5e90b545cf990c5000010" 有人有类似的问题,还是我幸运? 编辑:我已经添加了代码: http ://pastie.org/5901177在该代码中,我创build3个客户端,并推入到user.clients数组。 之后,我在user.clients数组的顶部添加了一个更多的客户端。 所以当我这样做 […]

如何在应用程序path中使用socket.io

我用nodejs开发了我的第一个项目。 我使用express 3作为框架和客户端服务器通信的socket.io 。 目前我正在创build一个registry格。 它工作得很好,但我不知道如何使用socket.io并正确地一起express 。 我检查电子邮件和密码是否有效,如果不是,我想推送一个json对象的客户端。 我使用这个应用程序路线: app.post('/user', function (req, res) { var user = new User(req.body.user), errors; function userSaveFailed() { res.render('index'); } errors = user.validation(req.body.user.confirm); user.save(errors, function (err) { if (err) { // Here I would like to send the Object to the client. io.sockets.on('connection', function (socket) { socket.emit('registration', { errors : […]

发布一个base64图像Imgur

http.get('http://path/to/image.jpg', function (res) { var img = ''; res.on('data', function (buff) { img += buff; }); res.on('end', function () { var data = querystring.stringify({ image: img.toString('base64'), type: 'base64' }); var opts = { host: 'api.imgur.com', path: '/3/image', method: 'POST', headers: { 'Authorization': 'Client-ID myId', 'Content-Type': 'application/x-www-form-urlencoded', 'Content-Length': data.length } }; var req = https.request(opts, function […]

Express 3.0 + Everyauth + HTTPS

我正在使用expression式3和everyauth为google oauth的nodejs。 实现如下所示: everyauth.google /* snip */ .callbackPath('/loggedin'); var app = express(); app.configure(function(){ /* snip */ app.use(everyauth.middleware()); } var server = https.createServer(sslOptions, app); server.listen(app.get('port'), function(){ // … }); 现在,当我去到谷歌loginpath它说: 请求中的redirectURI: http://localhost:4545/loggedin与注册的redirectURI不匹配 这是正确的,因为我只在google api控制台中添加了httpS URI。 请注意,我正在使用HTTPS(secure!),并且由于某种原因,everyauth会用httpreplace我的url中的https。 我想这可能是因为我在app.use(everyauth.middleware());之后创build了https服务器app.use(everyauth.middleware()); 声明。 但是,如何重写代码,以便everyauth不会忽略https? 有没有移动app.use(everyauth.middleware());的可能性app.use(everyauth.middleware()); 在创buildhttps服务器之后的地方声明? 提前致谢!

快速parsingreq.body中的multipart / form-data post

我试图使用在Chrome浏览器和Firefox浏览器上find的jQuery Ajax + FormData对象来上传文件。 我正在使用的代码如下: var formData = new FormData(); formData.append('image', $scope.image.data); $.ajax({ url: '/wines/'+id+'/image', type: 'POST', data: formData, processData:false, contentType:false }).done(function(){ $location.path('/'); }); 通过查看开发人员工具,我可以看到请求形成正确,但是express是识别req.body内的内容而不是req.files。 这是请求有效载荷图像: 快速configuration: app.configure(function(){ app.set('views', __dirname + '/app'); app.engine('.html', require('ejs').renderFile) app.use(express.static(__dirname + '/app')); app.use(express.bodyParser()); app.use(express.methodOverride()); app.use(app.router); }); 我做错了什么? 非常感谢。

使用摇篮如何在沙发数据库中创build新的数据库

在我的应用程序im使用node.js连接与couchdb.Im新的沙发数据库,​​所以我不知道如何连接与沙发数据库使用cradle.Please帮我在这个。我试了下面的代码,但新的'testing'数据库不创build。 var cradle=require('cradle'); cradle.setup({ host: 'https://mydomain.iriscouch.com', cache: true, raw: false }); var c = new(cradle.Connection); var db = c.database('test'); db.create();

JavaScript方法链接,从数组中添加方法

嗨,我想知道你是否可以帮助我dynamicbuild立一个方法链,我怀疑这很容易做到,如果你知道如何… 使用mongoose和node.js我正在查询一个mongo数据库。 我使用一个函数来传递一个对象,如下所示: transaction = { model: a mongoose model req: Express.js request object res: Express.js response object query: a mongo db query eg, {_id:xxxxx} populate: [ { field: 'name_of_doc_field' select: 'field1,field2' } ] } 我dynamic构build查询,并且在函数中,我不知道需要填充多less个字段,或者是否需要偏移量或限制。 我想链接我的发现: transaction.model.find(transaction.query).skip(offset).limit(limit).exec(function(err, collection_obj){…}) 我如何dynamic构build这个链,我需要testing一个偏移量是否在testing对象中提供,如果是将.skip方法添加到链中等等,并且使用填充方法,将会有一个项目数组,该数组中的每个项目都需要添加到链中的新的填充方法。 最后,我需要一个exec方法到链的末尾。 感谢您的帮助提前 // Generated by CoffeeScript 1.4.0 module.exports = { findMany: function(transaction) { var collection_obj, […]

express3 – 试图路由文件

我试图在express3路由文件,但我遇到了一个问题。 所以这里是路由文件的代码 – var app = require('express')(), server = require('http').createServer(app), io = require('socket.io').listen(server); server.listen(8080); // routing app.get('/', function (req, res) { res.sendfile("index/index.html"); app.use(app.static(__dirname + 'index')); }); 当我在Chrome中打开localhost:8080 ,它给我一个错误: TypeError: Object function app(req, res){ app.handle(req, res); } has no method 'static' 我做错了什么? 我所有的HTML / CSS / JS文件都在索引目录中。