fs

Does the free tier of Heroku apps support file upload?

耗尽温柔 提交于 2021-01-29 10:42:00
问题 I am testing out a MEAN stack application. I have a Node.js backend which handles file upload (via fs/multer ). However I'm receiving a 503 error when trying to hit it in production. Locally everything is working fine. I am using Heroku's free tier; is that tier locked to not allow file upload? The upload I'm trying currently (have tried several) is only 36kb ( .png ). Went through my logs and found the 503- 2018-10-26T20:39:24.352297+00:00 heroku[router]: at=error code=H13 desc="Connection

TypeError: fs.readFileSync is not a function

|▌冷眼眸甩不掉的悲伤 提交于 2021-01-29 08:59:02
问题 My project require to use filesystem module in ReactJS. The project was created with create-react-app. In one of the component js file, I need to load lines in a textfile from a directory. var fs = require('fs'); var readline = require('readline'); var stream = fs.readFileSync( C:/data/localmap.txt" ).toString().split("\n"); ....... There isn't error in the terminal, but the browser shows error as shown below: TypeError: fs.readFileSync is not a function Different from the issue raised here,

Mock 'fs' module in jest

你说的曾经没有我的故事 提交于 2021-01-29 04:13:39
问题 I'm trying to mock the fs module like so: jest.mock('fs'); And as seen in this post - Mock fs function with jest I should be able to treat the functions inside the module as jest.fn() and use - fs.existsSync.mockReturnValue(false); for instance. That however does not seem to work and typescript gives me a bunch of errors. All I want to do is assert a couple of functions like mkdirSync to have been called times or with some parameters and I seem to be running into this error - 'The "path"

“fs is not defined” How can I use fs within a VueJS file

感情迁移 提交于 2021-01-28 17:48:03
问题 I have been researching online and many others have ran in to similar problems that were left unresolved. Why is that I can't use fs in VueJS file, I have read that it cannot be called on the client side however it is used within the docs so what am I doing wrong? https://socket.io/docs/client-api/#With-a-self-signed-certificate socket.js file: const fs = require('fs'); var https = require('https').createServer(app, { key: fs.readFileSync('server-key.pem'), cert: fs.readFileSync('server-cert

How to avoid the error in angular :- (node:19100) ExperimentalWarning: The fs.promises API is experimental?

匆匆过客 提交于 2021-01-28 09:06:16
问题 I am getting this warning when running the command ng serve. How can I uninstall fs-extra? Or what is the other way around to avoid this error? 回答1: Update your Node.js version. I was getting this warning in Angular v10 projects running on Node v10. I updated Node.js to LTS version (currently 14.5) and the warning was gone. According to Angular docs: Angular requires a current, active LTS, or maintenance LTS version of Node.js. So basically it does work on version 10 atm, but it's always a

fs.createWriteStream over several processes

旧时模样 提交于 2021-01-28 01:47:40
问题 How can I implement a system where multiple Node.js processes write to the same file with fs.createWriteStream , such that they don't overwrite data? It looks like the default setup for fs.createWriteStream is that the file is cleared out when that method is called. My goal is to clear out the file once, and then have all other subsequent writers only append data. Should I use fs.createWriteStream and then fs.appendFile ? Or is there a way to open up a stream for each process, not just for

How can i open a Windows-1255 encoded file in Node.js?

佐手、 提交于 2021-01-27 05:01:54
问题 I have a file in Windows-1255 (Hebrew) encoding, and i'd like to be able to access it in Node.js. I tried opening the file with fs.readFile , and it gives me a Buffer that i can't do anything with. I tried setting the encoding to Windows-1255 , but that wasn't recognized. I also checked out the windows-1255 package, but i couldn't decode with that, because fs.readFile either gives a Buffer or a UTF8 string, and the package requires a 1255-encoded string. How can i read a Windows-1255 -encoded

Encrypting file in Node via Crypto and Stream

两盒软妹~` 提交于 2020-12-16 06:11:47
问题 I want to read from a stream then encrypt it and finally write it to another file. This is my code: var fs = require('fs'); var crypto = require('crypto'); var infile = fs.createReadStream('a.dmg'); var outfile = fs.createWriteStream('b.dmg'); var encrypt = crypto.createCipher('aes192', 'behdad'); var size = fs.statSync('a.dmg').size; console.log(size); infile.on('data',function(data) { var percentage = parseInt(infile.bytesRead) / parseInt(size); console.log(percentage * 100); var encrypted

How to download image into local storage?

时光毁灭记忆、已成空白 提交于 2020-12-15 04:57:09
问题 I am use Node.js Firebase Cloud Function but need get image I have store in Firebase Storage so I can send to Google Cloud vision API. Vision API require send from local image file: // const fileName = 'Local image file, e.g. /path/to/image.png'; // Performs safe search detection on the local file const [result] = await client.safeSearchDetection(fileName); const detections = result.safeSearchAnnotation; How to download remote image into local storage? For example I want store this image in

How to download image into local storage?

只愿长相守 提交于 2020-12-15 04:55:00
问题 I am use Node.js Firebase Cloud Function but need get image I have store in Firebase Storage so I can send to Google Cloud vision API. Vision API require send from local image file: // const fileName = 'Local image file, e.g. /path/to/image.png'; // Performs safe search detection on the local file const [result] = await client.safeSearchDetection(fileName); const detections = result.safeSearchAnnotation; How to download remote image into local storage? For example I want store this image in