Tag: asynchronous

Mongoose + Node.js:asynchronous问题

我在ReadyForReview集合中有一堆configuration文件。 每个configuration文件都包含一个“user_id_to_review”字段。 我想使用user_id_to_review将Users集合中的用户信息附加到每个configuration文件。 // looking for all ReadyForReview profiles ReadyForReview.find() .exec(function(err, profilesReadyForReview) { var profilesReadyForReviewArray = [] //array that will be populated with profiles and user info // for each profile, figure out what the info for the user is from user table for (var i = 0; i < profilesReadyForReview.length; i++) { var thisUserProfile […]

来自child_process的node.js:console.log

在节点中,我使用child_process运行perl脚本,并且callback中的console.log似乎performance得很奇怪。 child = exec("perl " + validationScript, {cwd: myDir}, function(err, stdout, stderr) { console.log('stdout: ' + stdout); console.log('stderr: ' + stderr); return cb(err); }); stdout打印正确,但stderr打印语句不执行。 (如果我注释掉标准输出,则stderr被正确打印)。 那么一些缓冲的问题? 我怎样才能让他们打印正确? 我是新来的asynchronous编程,所以很抱歉,如果这个问题太基本。

如何正确构buildasynchronous节点代码

我试图通过我所拥有的“事件”数据库来工作,并根据每个事件的位置,半径,开始时间和结束时间从Instagram API中提取照片。 我已经在我的Node服务器上设置了下面的代码,但它不像我所期望的那样运行。 当我运行这个代码时,我看到的第一件事就是sending request to Instagram for [name] with min_timestamp: [timestamp]为每个事件打印sending request to Instagram for [name] with min_timestamp: [timestamp] 。 我没有想到这一点。 我希望看到这行logging的第一个事件,然后更新一个新的时间戳,直到该事件达到其结束时间。 然后事件2,遍历时间戳,等等。 最后,我会为每个事件重复一遍又一遍的相同的照片。 就好像我的代码一遍又一遍地向Instagram发出一个请求(带有初始时间戳),然后停止。 关于我的时间戳variables的注意事项:对于每个事件,我将我的minTimestampvariables设置为初始等于我的数据库中的event.start 。 这在发送给Instagram的请求中使用。 Instagram返回20张照片给我。 每张照片都有一个created_timevariables。 我抓住最近的created_timevariables,并设置我的minTimestampvariables等于它( minTimestamp = images[0].created_time; )我的下一个请求发送到Instagram(抓住接下来的20张照片)。 这将继续,直到minTimestamp不再小于endTimestamp( event.end从我的数据库中的事件)。 server.js代码: // modules ================================================= var express = require('express.io'); var app = express(); var port = process.env.PORT || […]

摩卡它()testing只通过,如果没有事先testing

我正在testing一个MEAN应用程序。 每个testing只是确保我得到正确的回应代码。 在我的路由器中,他们使用res.send()成功返回json。 这里给出的第二个testing只有当第一个被注释掉时才会通过。 如果我把第一个testing评论出来,第一个testing通过,但第二个testing通过。 这种行为对于这两个testing不是唯一的。 在“接受经济长期”之前,还有另外一个考验。 如果我评论一下,接受经济和长期的工作。 如果我离开它,接受经纬度。 我需要做些什么才能让这些asynchronoustesting通过? 我曾尝试将超时设置为60秒,但这也不起作用。 var assert = require('assert'); var server = require('../bin/www'); var request = require('supertest'); request = request('http://localhost:3000'); describe('POST service request', function(){ this.timeout(5000); var postRequest = request.post('/requests.json').type('form'); … (other commented out tests) … // it('accepts lat and long', function (done){ // postRequest.send({ // service_code: 2000, // long: […]

根据最新的响应发送Node中的同步请求

我在我的Node服务器上使用asynchronous模块,以循环遍历MongoDB数据库中的对象,根据每个对象中的数据发出对Instagram API的请求,并在每次迭代中增加minTimestamp ,直到达到endTimestamp 。 下面的代码工作很好,除了一个大问题。 如果我通过一个硬编码的值( minTimestamp += 1000 )来增加minTimestamp ,那么所有的运行都很好。 然而,当我改变这一行代码来抓取最新的响应( minTimestamp = images[0].created_time )的最新created_time我的循环运行一次为每个'事件'然后停止。 我得到正确的递增的minTimestamplogging到我的控制台,但值似乎永远不会到下一个循环。 // modules ================================================= var express = require('express.io'); var app = express(); var port = process.env.PORT || 6060; var io = require('socket.io').listen(app.listen(port)); var request = require('request'); var Instagram = require('instagram-node-lib'); var mongoose = require('mongoose'); var async = require('async'); var […]

async.js方法中的async.js方法

免责声明:新的JS和周围的一切。 🙂 我想知道是否可以嵌套在另一个asynchronousfunction 我在节点中有一个瀑布方法: /** * POST new travel wish */ router.post('/add', function(req, res) { var db = req.db; console.log(req.body); // add properties: customer_id and timestamp var date = new Date(); //… var notif; async.waterfall( [ // find the User function(next){ db.collection(userCollection).findOne({_id: new ObjectId(req.session.userID)}, next); }, // insert a new travelwish function(user, next){ notif = […]

Mongooseasynchronous调用另一个模型使validation不可能

我有两个mongoose模式,看起来像这样: var FlowsSchema = new Schema({ name: {type: String, required: true}, description: {type: String}, active: {type: Boolean, default: false}, product: {type: Schema.ObjectId, ref: 'ClientProduct'}, type: {type: Schema.ObjectId, ref: 'ConversionType'}, }); 然后将这个模式embedded到如下所示的父模式中: var ClientCampaignSchema = new Schema({ name: {type: String, required: true}, description: {type: String}, active: {type: Boolean, default: false}, activeFrom: {type: Date}, activeUntil: {type: Date}, […]

django < – >应用程序服务器(node.js)之间的通信方法?

一个客户端与Django交谈,而Django使用node.js来做一些与javascript相关的工作,为客户端返回一个http响应。 我想知道如何设置django和node.js之间的链接(?)。 简单地说,我可以使用Python的请求库和谈话http,但这是我能做的最好的? 如果我要在c ++中build立通信链接,我将使用Send / Recv Thread创build非阻塞套接字,并在django视图代码和send / recv线程之间使用互斥锁(或类似的)。 我想这就是node.js世界中所谓的asynchronous io 。 在python中是否有类似的东西,以便我可以在Django端与另一台服务器通信? 我听说很多大公司使用Thrift ,它会适合在这里吗? 我也看到gevent可能是相关的关键字在这里,但不知道。

JavaScript在async.map期间删除项目

我使用async.map迭代数组并执行每个项目上的一些asynchronous函数。 在某些情况下,我需要从原始数组中删除项目,我想知道这是否可能,我试着用两个空参数调用callback, cb(null,null) 但是这不起作用。 我尝试了一下,但在这个特定的情况下找不到任何东西。 有没有办法实现这一点? 谢谢。 编辑:短代码片段 async.map(page['canvasData']['objects'], function (elem, cb) { if (elem['type'] == "picturebox") { //async opeartions cb(null, elem); } else cb(null, null); }

摩卡超时无论如何都超过了

我目前正在摩卡书写我的nodejs应用程序的testing。 我的API调用要求我login,所以我想创build一个包装testing套件,创build一个testing用户,然后调用实际的testing套件。 下面是代码的样子: var request = require('supertest'); var config = require('../config/config'); var AdminUser = require('../models/Authmodel'); function configureAuth(test_suite) { var url = "localhost:" + config.port; var email = "test@test.com"; var password = "test_password"; var admin; var token; describe("Signup User", function() { it("should signup new user", function(done) { request(url) .post('/auth/signup') .send({ email: email, password: password }) .expect(200) […]