Tag: 包pipe理器

Node.js产生:如何检查进程立即退出

在我的应用程序中,我需要产生一个debugging程序进程给予一个转储文件进行debugging,说“example.dmp”。 如果找不到转储文件,则不是转储文件。 该过程将成功产生,但会立即退出。 我想在asynchronous函数中抛出一个错误消息,稍后可以尝试捕获。 const spawnDebuggerProcess = (debuggerConfigs) => { let debuggerProcess = spawn(config.debuggerName, debuggerConfigs) debuggerProcess.on('exit', (code, signal) => { console.log('pid ' + `${debuggerProcess.pid}`) console.log('child process exited with ' + `code ${code} and signal ${signal}`) }) debuggerProcess.on('error', (error) => {}) if (debuggerProcess.pid !== undefined) { return debuggerProcess } throw externalError.createError({ name: externalError.SPAWN_DEBUGGER_PROCESS_ERROR, description: 'Failed to […]

将节点6.10.3安装为NPM依赖项

处理使用无服务器框架部署到AWS Lambda的项目 ,我希望运行AWS Lambda上可用节点的相同版本 – 即节点6.10.3。 添加到“引擎”没有任何作用,所以我也把它添加到“依赖” ,但安装该依赖总是失败: > node@6.10.3 preinstall /Users/ssterling3/Documents/2017/IIT/Apps/Student Dashboard/mobile-dashboard/node_modules/node > node installArchSpecificPackage npm ERR! code ETARGET npm ERR! notarget No matching version found for node-darwin-x64@6.10.3 npm ERR! notarget In most cases you or one of your dependencies are requesting npm ERR! notarget a package version that doesn't exist. npm ERR! A […]

通过不同的可读stream对相同的可写stream进行两次pipe道操作

我试图连接一个string和一个可读stream(可读stream指向一个文件,可能有多个数据块,即文件可能很大)到一个可写入的stream,以便可写入的stream可以最终写入到一个目的地。 我正在encryption文件的string和内容,然后对它们应用zlib压缩,最后我想pipe他们到可写入的stream。 要做到这一点,我可以: a)将文件内容转换为一个string,然后连接string然后encryption,进行压缩,然后将其pipe道化为可写入的stream。 但这是不可能的,因为文件的大小可能很大,因此我不能将其内容转换为string。 b)我可以先encryption和压缩string,然后将string转换成stream,然后将其完全传输到可写入stream中,然后将文件内容传送到相同的可写入stream中。 为此,我写了这个: var crypto = require('crypto'), algorithm = 'aes-256-ctr', password = 'd6FAjkdlfAjk'; var stream = require('stream'); var fs = require('fs'); var zlib = require('zlib'); // input file var r = fs.createReadStream('file.txt'); // zip content var zip = zlib.createGzip(); // encrypt content var encrypt = crypto.createCipheriv(algorithm, password, iv); var w = […]

如何防止pm2在启动过程中出现错误时重新启动应用程序

上下文 我已经将configurationvalidation添加到组成我的Node.js应用程序的一些模块中。 当他们开始时,每个人检查它是否正确configuration,并有权访问它需要的资源(例如可以写入一个目录)。 如果它检测到有什么错误,它会向自己发送一个SIGINT(process.pid),这样应用程序就会正常closures(closureshttp服务器,closures与Redis的连接等等)。 我希望操作员在启动应用程序之前,意识到存在configuration和/或环境问题并对其进行修复。 我使用pm2开始/停止/重新加载应用程序,我喜欢事实pm2会自动重新启动它的情况下,以后崩溃,但我不希望它重新启动我的应用程序在上面的情况下,因为根本原因不会只需重新启动应用程序即可消除,所以pm2将继续重新启动max_restarts (默认为max_restarts中的10)。 题 如何防止pm2在启动过程中中止重新启动应用程序? 我知道–wait-ready有–wait-ready选项,但是由于我们正在讨论多个模块和asynchronous启动逻辑,所以我很难确定何时/何时process.send('ready') 。 可能的scheme 我正在考虑让我的所有模块发出一个内部的“准备好”事件,并把所有连接“准备好”事件的事情连接起来,最终能够将“准备好”发送给pm2,但是我想先问一下,有点过于工程。 谢谢, 罗杰

如何gzip通过pipe道readStream传递的内容

我目前正在开发一个项目,要求在将内容发送回浏览器之前将其内容进行gZip编辑。 我目前正在使用一个简单的阅读stream和pipe道数据的请求的响应,但我不知道最好的方式来gzip内容没有阻止请求 发送数据的行是: require('fs').createReadStream(self.staticPath + Request.url).pipe(Response); 看到下面的类是静态处理程序对象: (function(){ var StaticFeeder = function() { this.staticPath = process.cwd() + '/application/static'; this.contentTypes = require('./contenttypes') } StaticFeeder.prototype.handle = function(Request,Response,callback) { var self = this; if(Request.url == '/') { return false; } if(Request.url.indexOf('../') > -1) { return false; } require('path').exists(this.staticPath + Request.url,function(isthere){ /* * If no file exists, pass back […]

使Ruby与Node.js交互

我正在使用Ruby EventMachine来构build一个实时Web应用程序,到目前为止一切正常,但我想添加一个function,哪个Node.js有一个包,Ruby不( 节点帆布 )。 我想用Node.jsreplace整个应用程序,但我更喜欢用JavaScript编写Ruby代码。 此外,我对Node.js完全陌生,尽pipeWeb应用程序代码并不是非常复杂,但是需要时间从头开始用Node重写。 有没有一种简单的方法,我的Ruby代码可以与Node.js模块进行交互,我将专门为此function构build,也许通过pipe道或什么?

pipe理处理以提取Node.jssubprocess中的tar缓冲区

我想通过Node.js来做到这一点: git archive remote=git@example.com:repo.git HEAD | tar -x – -C /path/to/extracted/ 所以,我写了这样的代码: git = spawn 'git', ['archive', "–remote=git@example.com:repo.git", 'HEAD'] tar = spawn 'tar', ['-x', '-', '-C /path/to/extracted'] git.stderr.on 'data', (data) -> console.log "git error: #{data}" git.stdout.on 'data', (data) -> tar.stdin.write data tar.stderr.on 'data', (data) -> console.log "tar error: #{data}" git.on 'exit', (code) -> console.log "git […]

node-supervisor不启动我的节点服务器

如果我运行(从我的项目目录中): supervisor javascripts/index.js 我得到:/ usr / bin / env:node:没有这样的文件或目录 如果我运行: node javascripts/index.js 它正确启动我的服务器。 有谁知道我可能做错了什么,或明白这个错误信息是想告诉我什么?

如何使用Node.js createReadStream和createWriteStream编写多个文件

好的,这里是这个代码的总体目标。 我正在使用TinyPNG的API来压缩png文件的文件夹。 我有一个名为filename.png的文件的input文件夹。 此代码将文件名的目录读取到数组文件中,然后为要发送到API的文件创build读取和写入stream,进行处理,然后返回,以便将其写入输出文件夹中的文件。 我知道这个代码对于一个文件是有效的,但是不止如此,抛出了一个写完之后的exception,因为pipe道在第一个文件后自动closures。 我试图设置input和输出作为数组,只是引发另一个exception。 任何提示如何设置多个读取和写入stream将是真棒和非常有用的每个人:)。 当前代码: var fs = require('fs'); var inputFolder = "input/"; var outputFolder = "output/"; var https = require("https"); var key = "GETYOUROWNFREEONEFROMTINYPNG.ORG"; process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; var options = require("url").parse("https://api.tinypng.com/shrink"); options.auth = "api:" + key; options.method = "POST"; console.log("Reading files…"); fs.readdir("./input", function (err, files) { if (err) throw err; console.log(files.length […]

通过套接字连接将https代理请求pipe道传输到命名pipe道(node.js)

我正在尝试构build一个转发代理服务器,它可以请求一个http url,并将请求传递给在已命名pipe道上侦听的https服务器。 我知道我错过了一个步骤,但我不确定它是什么。 这是我正在尝试使用… function pipeToServer(browserRequest, browserSocket, browserRequestHead){ var targetUrl = url.parse('https://' + browserRequest.url); var namedPipe = getNamedPipe() console.log("Attempting to connect to " + namedPipe) var proxySocket = net.connect(namedPipe, function() { console.log("Connected to destination server: " + namedPipe) console.log("Sending head: " + browserRequestHead) browserSocket.write('HTTP/' + browserRequest.httpVersion + ' 200 Connection Established\r\n' +'Proxy-agent: Node-Proxy\r\n' + '\r\n'); […]