fs

Append string to a text file Nodejs in AWS Lambda

雨燕双飞 提交于 2019-12-12 20:24:26
问题 The scenario: A text file snapshot-ids.txt is located in a S3 bucket. I'm trying to create a Lambda function that run daily (Cron) that would use AWS CLI to take snapshot of a volume, then save that snapshotId to a text file in S3. On the next time another snapshot is created, the new snapshotId will be saved to the same text file on S3. The text file is a place holder for snapshotIds and when it reaches a threshold, it will delete the top snapshotIds and add the new one at the end (FIFO pipe

Why node 10 has made it mandatory to pass callback on fs.writeFile()?

帅比萌擦擦* 提交于 2019-12-12 17:50:48
问题 Suddenly, I started getting this error on my application when the node engine was upgraded to 10.7.0 TypeError [ERR_INVALID_CALLBACK]: Callback must be a function Code which was working with node 4.5: fs.writeFile(target, content); After a bit of debugging I found this in node_internal/fs.js: function writeFile(path, data, options, callback) { callback = maybeCallback(callback || options); ... } function maybeCallback(cb) { if (typeof cb === 'function') return cb; throw new ERR_INVALID

Difference between fs.exists and fs.existsSync

谁说我不能喝 提交于 2019-12-12 16:09:55
问题 While working with the file I/O for node I found these two functions( fs.exists and fs.existsSync ) to check if a file exists in the system. What are the differences between them? 回答1: exists is non blocking, and you do subsequent work with the file through a callback. existsSync is blocking and freezes your whole app while it is working. This can be appealing to new node users because they can continue their code on the next line. However, once you become used to using callbacks, this is a

Check permission before stat method to avoid errors

大憨熊 提交于 2019-12-12 14:16:03
问题 My first time ever trying to traverse directories, but stat is throwing errors for some of the directories due to what seems to be a lack of permission. Error: EPERM: operation not permitted, stat 'K:\System Volume Information' I'd like to simply avoid calling stat on a given directory in the first place if it is going to throw an error, yet I can't figure out how to do it. I've tried looking into ignoring protected directories altogether. However, all of the questions I came across used

How to use FS when MODULARIZE and EXPORT_NAME are used in emscripten

非 Y 不嫁゛ 提交于 2019-12-12 12:19:01
问题 I have an application that contains libraries generated with emscripten. I am compiling them using the flags: -s MODULARIZE=1 -s EXPORT_NAME=\"'SomeModuleName'\" However, the library FS is no longer available. When I was compiling without the flags, I could use the library FS in any other script. Is it possible to export FS in my module? 回答1: The FS module is not exported by default when using the flag -s EXPORT_NAME="'SomeModuleName'" If you want to export the module FS, you have to add the

Node.js Error ENOENT, open “file/path” when nothing has been changed

安稳与你 提交于 2019-12-12 10:35:44
问题 Ok first off... I'm new to Node.js. I'm trying to convert a word document to HTML then scrapping it to obtain the content. Then pump it into an existing engine. With that being said, everything was running fairly smoothly until today. I just got the fs.writeFile working last night and stepped away from it. This morning without touching it and trying to run it I receive this: here's the block where the error is being called. //COPY TEMPLATE AND PASTE fs.readFile("./Templates/TextBasedEvent.xml

Creating a .wav file in Node.js with fs.writeFile()

做~自己de王妃 提交于 2019-12-12 08:54:47
问题 I'm attempting to create a .wav file from a blob of data in Node JS, using fs.writeFile() . Firstly, is this even possible? I'm currently trying with this... fs.writeFile(filename + '.wav', blob.recording, function (err) { // On completing writeFile, transfer file via scp var options = {...}; var target_path = "the/path" if (err) return logger.error(err); else{ scp2.scp(options, target_path, function (err) { // scp2 callback: always gets here }); } }); The scp of the written file "completes"

meteor write file on meteor.com

假如想象 提交于 2019-12-12 06:47:23
问题 I want to deploy a meteor app to meteor.com. Unfortunately I have to write some tmp files to the public folder of meteor. Example Code: var fs = Npm.require('fs'); var filepath = "../../../../../public/resizing/tmp~"; fs.open(localpath, 'w', function(err,fd) { if(err) throw "error opening file"; fs.close(fd,function(){}); } ( ../../../../../public is the location of the meteor public folder after bundling! ) This works fine on my local machine, because I have write privileges inside the

createWriteStream 'close' event not being triggered

烈酒焚心 提交于 2019-12-12 04:59:02
问题 I am trying to extract images from a csv file by doing the following: Parsing/streaming in a large csv file using csv-parse and the fs createReadStream method Grabbing each line for processing using stream-transform Extraction of image and other row data for processing using the async waterfall method. Download and write image to server using request and the fs createWriteStream method For some reason after the data gets piped into createWriteStream , there is some event in which an async

File System Nodejs: “Uncaught TypeError: fs.writeFileSync is not a function”

ε祈祈猫儿з 提交于 2019-12-12 03:23:51
问题 I am not able to use the File System module of Nodejs. I have gone through many forums - applied the suggested fixes - and I'm still not able to use fs. My config.js file includes this as is suggested by https://github.com/request/request/issues/1529 : node: { console: true, fs: 'empty', net: 'empty', tls: 'empty' }, This is my main file: ... var fs = require('fs'); ... onGo(e){ e.preventDefault(); var json = { foo: 'bar', qux: 'moo', poo: 123 } var xls = json2xls(json); //everything runs