草庐IT

existing_event

全部标签

events - 如何让 nodejs 服务器监听 AWS SQS?

在详细解释问题之前,我先告诉你我目前的做法。我有一个运行setInterval()的js脚本。并且每个间隔,我都会调用SQS从队列中获取消息。如果有消息,那么我处理它。因此,它将无限运行,直到我终止该进程。我之前也建过一个Node服务器(使用nodejs.org中的例子)所以,我想知道的是,...而不是让setInterval定期运行。有没有办法,如果SQS中有一条新消息,那么它会触发一个事件并处理该消息? 最佳答案 这个问题已经超过2年了..但是有比更改轮询间隔更好的方法。而是将队列的接收消息等待时间设置为最长20秒。然后您可以进

events - 如何在 node.js (express.js) 中创建自定义事件监听器?

我有一个带有很多嵌套回调的巨大函数。我想让它更干净,更容易处理。所以,我正在考虑使用自定义事件监听器就像,当一个函数完成后,在回调中,而不是放一大块代码,它只是发出一个事件,然后监听器就会运行。那么,如何在node.js中做到这一点?我仍在寻找一个很好的例子来指导我。 最佳答案 你可以这样设置事件app.on('event:user_created',callback);然后你可以发射它们app.emit('event:user_created',data);express.js使用EventEmitter。

javascript - Node js+错误: listen EADDRINUSE + Unhandled 'error' event

我正在使用eclipse的nodeclipse插件来运行我的Nodejs项目。以下js文件工作正常,但h1标记不工作.我只能看到纯文本。另外我在运行时遇到了这个异常。请帮帮我。javascript文件varhttp=require('http');http.createServer(function(request,response){response.writeHead(200,{'Content-Type':'text/html'});response.end('HomeURLwas:'+request.url+'');}).listen(3000,'localhost');con

node.js - typescript 错误 : Property 'user' does not exist on type 'Request'

我的express应用中有以下代码router.get('/auth/userInfo',this.validateUser,(req,res)=>{res.json(req.user);});我的IDE似乎在提示这个错误errorTS2339:Property'user'doesnotexistontype'Request'.当我编译我的typescript代码时,它似乎抛出了这个错误。任何想法为什么会发生这种情况? 最佳答案 我们有一个用Express和Typescript编写的大型API,这就是我们处理此类场景的方式:我们将请

node.js fs.exists() 将被弃用,改用什么?

根据documentationnode.jsfs.exists()将被弃用。他们的推理:fs.exists()isananachronismandexistsonlyforhistoricalreasons.Thereshouldalmostneverbeareasontouseitinyourowncode.Inparticular,checkingifafileexistsbeforeopeningitisananti-patternthatleavesyouvulnerabletoraceconditions:anotherprocessmayremovethefilebetwe

node.js - NodeJS : throw er;//Unhandled 'error' event (events. js:72) 使用 child_process spawn 方法时

我制作了一个node.js应用程序,以递归方式列出目录中的所有.txt文件,并对每个文件执行一些操作。这是我的app.js:varspawn=require('child_process').spawn,dir=spawn('dir',['*.txt','/b']);dir.stdout.on('data',function(data){//dosomestuffwitheachstdoutline...console.log('stdout:'+data);});dir.stderr.on('data',function(data){//throwerrorsconsole.log(

node.js - 来自 Node-aws : all operations fail "Cannot do operations on a non-existent table" 的 Dynamo Local

我有一个本地dynamo-db正在运行。我已经使用JavaScript控制台设置了我的表,它们从那里列出了OK。我还可以从JavaScript控制台向我的表中放置和获取项目:varparams={TableName:"environmentId",Item:{environmentId:{"S":"a4fe1736-98cf-4560-bcf4-cc927730dd1b"}}};dynamodb.putItem(params,function(err,data){console.log("put:errwas"+JSON.stringify(err)+"anddatais"+JSON.

javascript - nodejs fs.exists()

我正在尝试在Node脚本中调用fs.exists但出现错误:TypeError:Object#hasnomethod'exists'我尝试将fs.exists()替换为require('fs').exists甚至require('path').exists(以防万一),但这些都没有在我的IDE中列出方法exists()。fs在我的脚本顶部声明为fs=require('fs');并且我以前用它来读取文件。如何调用exists()? 最佳答案 您的require语句可能不正确,请确保您有以下内容varfs=require("fs");f

node.js - 如何修复 'Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist.'

在我的Node/Express/React应用程序的每次页面加载时,Chrome开发工具控制台中都会出现以下错误:Uncheckedruntime.lastError:Couldnotestablishconnection.Receivingenddoesnotexist此错误引用了localhost/:1。当我将鼠标悬停在它上面时,它会显示http://localhost:3000/,这是我在浏览器中查看应用程序的地址。有人知道发生了什么吗?我发现的大多数其他引发此错误的线程似乎都与尝试开发Chrome扩展程序的人有关,即便如此,他们往往也很少得到响应。

node.js - fs.exists、fs.existsSync - 为什么不推荐使用它们?

我注意到官方Node文档对fs.exists的描述令人吃惊:"fs.exists()isananachronismandexistsonlyforhistoricalreasons.Thereshouldalmostneverbeareasontouseitinyourowncode.Inparticular,checkingifafileexistsbeforeopeningitisananti-patternthatleavesyouvulnerabletoraceconditions:anotherprocessmayremovethefilebetweenthecallstof