Tag: node.js

快速/节点中的阻塞问题

我在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? 簇? 或者是其他东西?

Sails-mysql拒绝注册连接

我在AWS实例上安装了Sails应用程序,并安装了所有依赖项,但没有出现明显的问题。 但是,每次我尝试启动应用程序,我收到以下错误。 error: AdapterError: Connection is already registered 我还没有设法成功地提升帆上的实例和sails-mysql是新鲜安装的,所以不应该注册连接。 我采取了以下步骤来部署我的应用程序.. 设置一个MySql RDS实例(EU-West) 创build并build立了Ubuntu AMD-64 t2.micro EC2实例(EU-West) 安装了所有先决条件(Git,NVM,NodeJs,Sails等) 克隆我的帆船项目 安装了Sails的依赖关系 正确configurationSails的连接设置以使用我的RDS实例。 我知道我的连接设置是正确的,因为我已经能够在我的本地机器上运行Sails并连接到我的RDS实例,并且始终能够毫无问题地解除连接。 我也可以使用SequelPro连接到我的RDS实例,没有任何问题。 过去我曾经遇到过依赖关系的问题,但是设法解决了这些问题,并且没有在我的本地机器上或者EC2实例上。 在search了一段时间之后,我遇到了一些有类似问题的用户,但是用Waterline的拆解方法设法解决了这些问题,但我不确定如何实现这一点。 我已尽力提供尽可能多的信息,任何帮助都将受到大力赞赏。 风帆版本: 0.12.11 先谢谢你。

从Firebasefunction访问Google Site Verification API

我正在尝试使用Node.js的Firebase函数使用Google Site Verification API 。 Github的google-api-nodejs-client存储库中提供的READMEbuild议使用默认的应用程序方法,而不是手动创buildOAuth2客户端,JWT客户端或计算客户端。 我写了下面的例子,我尝试在本地(模拟function环境)上运行,并在Firebasefunction上远程运行: const google = require('googleapis'); google.auth.getApplicationDefault(function (err, authClient, projectId) { if (err) { console.log('Authentication failed because of ', err); return; } if (authClient.createScopedRequired && authClient.createScopedRequired()) { authClient = authClient.createScoped([ 'https://www.googleapis.com/auth/siteverification' ]); } const siteVerification = google.siteVerification({ version: 'v1', auth: authClient }); siteVerification.webResource.get({ id: 'test.com' }, {}, function (err, data) […]

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(); }) […]

我无法在节点中发出Web请求

我正在做一个简单的Http请求到谷歌的主页,而不是在控制台中logging数据显示此错误 错误:连接ETIMEDOUT 172.217.26.163:80 此外,我试图向谷歌的地理位置API请求,也没有得到我的任何数据。 这是我的代码(Google的主页版本) const http = require('http'); let req = http.request('http://www.google.co.uk', function(response){ console.log(response.statusCode); response.pipe(process.stdout); }); req.end(); 我也在代理服务器后面,可能是因为代理服务器?如果是,我该如何在node.js本身设置一个代理服务器。 我已经为npm完成了。

Laravel Elastic Beanstalk,无法安装运行npm?

我有我的Elastic Beanstalk与Laravel 5.4这里是我的02-node.config: commands: 01-install-node: command: "curl –silent –location https://rpm.nodesource.com/setup_8.x | s$ command: "sudo yum -y install nodejs" 和03-deploy.config container_commands: 01-laravel-deploy: command: "php artisan migrate" command: "php artisan config:clear" command: "php artisan config:cache" command: "php artisan route:clear" command: "php artisan route:cache" command: "npm install" command: "npm run prod" 在部署期间,我得到: ERROR: [Instance: i-018d9dd563f6ba0e6] Command failed on […]

在OSXterminal中找不到NPM Global Package CLI

我在安装express和express-generator并尝试使用express cli生成内容时遇到了问题。 当我使用npm install -g express和npm install -g express-generator ,但是在重新启动terminal之后,一切顺利,但是我不能使用快速文档 经过一番调查,我发现express和express-generator安装到: /usr/local/lib/node_modules/node/lib/node_modules 然而,在我的机器上工作的唯一软件包(像Yeoman,Grunt,我经常使用没有问题的东西)在这里安装: /usr/local/lib/node_modules/ 那么这里的交易是什么? 为什么我的install -g软件包进入node/lib/node_modules ? 我试过在我的.bash_profile使用export PATH=/usr/local/lib/node_modules/node/lib/node_modules:$PATH ,但是这似乎并没有帮助我。

不能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) => { […]