Tag: javascript

快速/节点中的阻塞问题

我在node.js中使用express了一些阻塞问题。 目前,我现在有这个代码: router.get('/Hello', function(req, res, next) { (async ()=>{ try{ await api.connect(); let result=await api.HandleSomethins(); await api.disconnect(); }catch(err){ console.log(err); } })(); return res.status(json(result)); }); 上面的代码没有问题,我只是使用async / await来同步一些繁重的加载过程。 然后我得到了一个情况如下: 1.UserA使用这个URL来连接我的node.js,而UserA正在等待响应。 2.UserB也在这个时候连接,所以node.js不能立即处理UserB的请求。 (注意)。我需要发送回应到用户客户端(iOS / Android)。 也许节点服务器将得到UserC,D等…在同一时间。 我该怎么办才能解决这个问题呢? child_proess? 簇? 或者是其他东西?

discord.js – 机器人超时

我最近用node.js创build了一个discord.js机器人。 但是,我无法启动我的机器人,因为它超时。 Error: Something took too long to do. at timeout.client.setTimeout (C:\Users\User\Desktop\tntbot\node_modules\discord.js\src\client\ClientManager.js:40:57) at Timeout.setTimeout (C:\Users\User\Desktop\tntbot\node_modules\discord.js\src\client\Client.js:422:7) at ontimeout (timers.js:386:14) at tryOnTimeout (timers.js:250:5) at Timer.listOnTimeout (timers.js:214:5) 这就是我一开始就得到的。 我检查了代码,它没有问题。 请帮忙。

在node.js中如何testing传递给渲染文件的对象

router.get('/', (req, res) => { User.find({}, (err, users) => { res.render('users/index', {users: users}); }); )); 在页面上呈现的数据没有问题。 我只是想找一个方法来断言{users:users} 像下面的东西… // testfile.js const user = {name: 'nate'} beforeEach((done) => { User.remove({}).then(() => { return User.insert(user); }).then(() => done()); }); it('should GET /users page', (done) => { request(app) .get('/users/') .end((err, response) => { assert(response.body === user); done(); }) […]

不能NPM当需要在test / index.js中需要selenium-webdriver的testing时启动

所以我正在尝试使用webpack和selenium-webdriver在JavaScript项目上进行testing。 但是,当我需要从test / index.js文件的testing文件,以便在浏览器中运行它们npm开始崩溃与一系列'无法解决模块'错误。 我所需testing的标题如下所示: //=> test/meal_test.js const assert = require('chai').assert; const webdriver = require('selenium-webdriver'); const Meal = require("../lib/meal.js") const until = webdriver.until; const frontEndLocation = "http://localhost:8080" describe('test meal object', function() { it('should meal info and food info', function() { const meal = new Meal({ "id": 1, "name": "Breakfast", "foods": [ { "id": 4, "name": […]

我无法在v-for loop |中绑定图像源 vue.js,node.js

我尝试在v-for循环中绑定图像源。 我的数组是由函数填充,而不是静态的。 我的代码看起来像: <section class="section"> <div class="container"> <div v-for="match in matches" class="card"> <img :src="match.avatar" alt=""> </div> </div> </section> 和 created() { ipcRenderer.send('get:all:champions') ipcRenderer.send('summoner:recent:matches:request') ipcRenderer.on('summoner:recent:matches:response', (event, matches) => { matches.splice(-15, 15) // -15, 15 this.matches = matches for (let match in matches) { ipcRenderer.send('matches:champion:avatar:request', { element: match, championId: matches[match].champion }) } ipcRenderer.on('matches:champion:avatar:response', (event, data) => { […]

Node.js AJAX删除403禁止

我尝试创build从服务器删除图像的方法。 现在我只想处理DELETE请求,并显示在控制台filePath …服务器不处理我的请求,并发送: jquery.min.js:4 DELETE http:// localhost:3000 / api / imagesbg / wedding-stock-2.jpg 403(禁止) 我做错了什么? 前(handlebars.js) {{#each images}} <div class="row"> {{#each this}} <div class="col-sm-4"> <img src="/images/background-slider/{{this}}" class="img-responsive img-thumbnail" alt="{{this}}"> <button type="button" class="btn btn-danger pull-right imgBgDel" file-name="{{this}}" > Delete </button> </div> {{/each}} </div></br> {{/each}} 脚本 $(function(){ $('.delete-msg').hide(); var url; $(".imgBgDel").on("click", function(){ var url = 'http://localhost:3000/api/imagesbg/' + […]

带有十进制数的node.js数字和knex中的舍入

在我的postgres表中,我有一个numeric (30,16)types的字段numeric (30,16) ,其中存储了许多小数的数字。 我需要计算这些数字。 我使用knex ,默认情况下,它返回这些值作为String所以为了有号码,我试过了: var types = require('pg').types types.setTypeParser(1700, 'text', parseFloat); 然而,这仍然是行不通的,例如从488.1456218300001000和我减去300我可以得到类似于188.1456218300001500 。 我需要做什么在node.js正确处理操作没有任何舍入错误?

将状态传递到回送oAuthcallback

我正在开发一个投票在我的网站上。 我只想要授权的用户投票。 所以我使用Facebook OAuthauthentication用户。 我的后端是build立在node.js和使用回环框架。 我正在使用passport-facebook lib执行所有授权的东西。 当用户按下投票button,后端检查用户是否被授权,并保存投票或否则redirect用户login页面。 一切都很好,但现在用户必须在授权后再次按下投票button。 我读到有一种方法可以将状态作为查询parameter passing到OAuthredirectURL。 这可以使用passport.js 完成 。 但是,回环隐藏实现,只提供静态jsonconfiguration。 至less我在docker和回购站里找不到任何提及。 所以我的问题是如何处理? 谢谢你的帮助。

使用父ID将子JSON对象移动到它们自己的对象

我对JavaScript非常陌生,正在使用Node.JS访问API并将响应存储在SQL Server中。 我正在使用“请求”和“mssql”节点包。 我不重视这些,他们似乎是我所需要的,并有良好的文件和支持。 我的问题:我有以下格式的API的JSON响应: requests = [ { url: 'https://domain.zendesk.com/api/v2/requests/2.json', id: 2, status: 'closed', priority: 'normal', type: 'incident', subject: 'Test Ticket', description: 'Test ticket', organization_id: 10101010101, via: { channel: 'email', source: { from: { address: 'bill.bob@domain.com', name: 'Bill Bob' }, to: { name: 'Company Helpdesk', address: 'testzendesk@domain.com' }, rel: null }, }, custom_fields:[ { […]

在帕格/翡翠dynamic包括解决方法

据我所知,帕格不支持在模板中dynamic包含或扩展。 即 extend path/to/template 工作但不是 extend #{dynamic_path_to_template} 有没有一个解决方法(无论是复杂的),将允许相同的目标,在运行时修改视图使用的模板 上下文 :我的用例是我正在开发一个npm模块,用于扩展其他视图的模板位于模块内部。 在模块发布和安装之后,path将被定义(即node_modules / my_module / path / to / template),但是在开发阶段,我只需要能够“npm link”到模块并拥有模板工作。 我也不想硬编码的链接,所以我可以发布相同的代码作为testing。