Tag: fs

当fs.ReadStream暂停时,nodejs是否暂停从硬盘读取文件?

有人知道,当fs.ReadStream暂停时,是什么引发的? 文件的读取是否继续,内容是否在后台被缓冲(占用的内存太多),或者它很聪明,不会从硬盘读取文件的其余部分,直到读取stream被恢复? 谢谢你的回答!

nodejs列出或删除所有文件和目录asynchronous只传递开始path

我一直在通过stackoverflow的主题来find有用的东西,什么都没有。 我需要的是(可能)一些模块,你可以这样调用: someModule('/start/path/', 'list', function(err, list) { // list contains properly structured object of all subdirectories and files }); 也是这个 someModule('/start/path/', 'remove', function(err, doneFlag) { // doneFlag contains something like true so i can run callback }); 我需要上述function来为我的学生创build迷你Web构build的ftp /代码编辑器。 列表中包含正确的不仅包含文件的结构,而且还包含子目录,这一点非常重要。它不一定非常像我想要的例子那样简单,最重要的是function就在那里。 谢谢你的所有推荐。

nodejs清空文件fs.writeFile / appendFile

我是一个用nodejs编写聊天loggingbot的新手。 现在它工作得很好。 几个小时后。 僵尸程序为每个用户创build一个文档,如果用户不存在这样的文档,如果它存在,那么它将input该文件。 这是我的代码: fs.open('logs/' + channel.substr(1) + '/' + user.username +'.txt','r',function(err,fd){ if (err && err.code=='ENOENT') { fs.writeFile('logs/' + channel.substr(1) + '/' + user.username +'.txt', '[' + 'GMT' + moment().format('Z ') + moment().format('DMYYYY H:mm:ss') + '] ' + user.username + ': ' + message + '\n', function (err) {}); } else { fs.appendFile('logs/' + […]

fs.writefile只能在节点js的最后一个函数中执行

我的程序有三个function如下所示, var userId = req.userId; var appId = req.body.appId; var main = 'temp/' + userId + '/templates/' + appId + '/css/main.css'; var color = req.body.color; var font = req.body.font; var fontSize = req.body.fontSize; replaceThemecolor(color); replaceFont(font); replaceFontSize(fontSize); function replaceThemecolor(color) { fs.readFile(main, 'utf-8', function (err, data) { var regex =/(\.made-easy-themeColor\s*{[^}]*color\s*:\s*)([^\n;}]+)([\s*;}])/; var result = data.replace(regex, "$1" + color […]

如果我发布模块到NPM fs不会得到文件

当我将模块发布到npm时,我遇到了一个问题。 这是文件结构: – node_modules – lib — file.txt – index.js – package.json 我这样使用: var a = fs.readFileSync('./lib/file.txt'); 它在当地发展。 但是,当我发布我的模块npm,它说: Error: ENOENT, no such file or directory './lib/file.txt' 这个错误来自fs,它没有得到文件。 是关于嵌套的node_modules文件夹吗? 我的意思是当我想testing我的模块在清除文件夹,我安装模块: npm install <my-module-name> 创build一个test.js文件并把它放在里面: var myModuleName = require('my-module-name'); var a = myModuleName(); console.log(a); 所以新的结构变成: – node_modules — my-module-name — node_modules — lib — file.txt — […]

节点js中的文件系统导致错误

fs.writeFile(); 当我上传图像导致问题。 BTW图像上传,但有一些服务器问题发生。 像502坏的网关和腻子,我可以看到像“ 永远检测到的脚本被杀死信号:SIGKILL ” 短代码 : fs.writeFile(userUploadedImagePath, imageBuffer.data, function(err ) { json_response['success'] = true; res.json(json_response); });

Javascript的Node.js完全覆盖文件

我有一个应用程序需要一个data.json文件,以绘制一个D3图。 不过,我需要在onClick -Event上更新该文件: d3.select("#updatebutton").on("click", function(e) { try{ $.get('https://localhost:4444/data', function(data) { }); } catch (e) { alert('Error: ' + e); } }); 以上是带有jquery调用的update-Button。 在我的app.js文件中,我使用它是这样的: app.get('/data', function(req, res, next) { try{ getJSON(); } catch(e) { alert('Error'); } }); getJSON()函数通过https-Request接收数据,处理该数据并将其保存到data.json : function getJSON() { var req = https.get(options, function(response) { // handle the response var res_data = ''; […]

如何从其他服务器获取映像到我的Express服务器并写入磁盘

我需要从另一台服务器获取一些图像到我的服务器。 我用superagent发送GET请求。 我得到了答复,但我怎样才能使用fs.createWriteStream将文件写入磁盘? 我想看finish事件。 我正在使用Express 4和Node.js 5.3.0 function getPhotos(array) { array.forEach(item => { request // superagent .get(url) .query({media_id: item}) .end((err, res) => { console.log(res.status); console.log(res.body); }) }) } res.body是缓冲区: <Buffer ff d8 ff e0 00 10 4a 46 49 46 00 01 01 00 00 48 00 48 00 00 ff e1 00 58 45 […]

使用Node.js的fs.readFile()返回出现string的行

我正在寻找一个n-grams(大约一百万行)的大外部文件来处理特定string的实例,并希望能够从出现该string的文件中返回整行。 想知道如果和如何这可能是可能的。 这是我的代码: composeLines = function(importantWords, cb) { var word = importantWords.shift(); fs.readFile("./w5_.txt", function(err, cont) { if (err) throw err; console.log("String"+(cont.indexOf(word)>-1 ? " " : " not ")+"found"); cb(importantWords); }); }; 有了这段代码,我可以确定文件w5_.txt包含一些很好的string,但是我需要能够得到它所属的n-gram。 例如,search“devise”会从文件中返回n-gram“devise的一部分”。 任何帮助,将不胜感激。

NODEjs在for循环中同步exec语句

我想创build一个程序,在这里我从目录中读取文件,然后在其他目录中grep这些名称。 这里是代码: var exec = require('child_process').exec; var internalCount = 0; var i = -1; for (; i < fileNamesInDir.length / 2;) { if (i === internalCount) { continue; } (function () { i = internalCount; var j = i; exec('grep -nre js/' + fileNamesInDir[j] + ' ./ –exclude-dir=node_modules –exclude=searchResults.txt', function (error, stdout, stderr) { outputString […]