fs

How can I handle a file of 30'000 urls without memory leaks?

。_饼干妹妹 提交于 2020-07-16 08:04:33
问题 Inside the .txt file there are 30.000 url to scrape, when I made the program I was testing it with 10 urls and everything was fine, as soon as I made the 30k url file .txt it crashes after few minutes, I think it starts to read the .txt file and then it crashes due memory issues, here is the console output and my code. What's the best way to handle such a file? FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory 1: 0x100ba0c4a node::Abort()

Use fs.watch but ignore node_modules

荒凉一梦 提交于 2020-07-10 08:47:08
问题 I am looking at the docs for fs.watch https://nodejs.org/docs/latest/api/fs.html#fs_fs_watch_filename_options_listener How can I watch all files in the current directory, but ignore node_modules? 回答1: Doesn't look like it's possible. Just take a look at the path in the listener and do nothing if it starts with 'node_modules'. It can't be that much of a performance hit, unless you're constantly updating modules while node is running, which would be a little strange. 来源: https://stackoverflow

Electron app createWriteStream throwing ENOENT error

自作多情 提交于 2020-07-09 13:55:09
问题 I'm trying to download files to the filesystem in an electron app. My code, in the main thread, looks like this: const dir = `${__dirname}/media`; if (!fs.existsSync(dir)){ fs.mkdirSync(dir); } const file = fs.createWriteStream(`${dir}/${name}`); file.on("open", function() { const request = http.get(url, function(response) { response.pipe(file); response.on('end', function() { file.close(); ... }); }); request.on('error', function(err) { ... }); }); This works when running in development

Argon2 is difficult to get working with Angular 8 on MacOS: actually not working at all

久未见 提交于 2020-06-28 03:45:14
问题 I am working with: MacOS Mojave Angular 8 node v12.12.0 npm v6.13.4 and trying to make Argon2 to work in my Angular 8 app. In order to use Argon2 it is required to install gcc and node-gyp globally. I did install them as indicated on the npm pages of Argon2. GCC v9 was installed. But, I had repeatedly problems executing: CXX=g++-9 npm install I kept getting errors about stdlib++ . I tried using Apple's CLang++ and got a successful build with: CXX=clang++ npm install I imported argon2 in my

How to copy a image?

ぐ巨炮叔叔 提交于 2020-06-24 10:14:49
问题 I want to copy image.png form /folder1 to /folder2 , how to do it? /folder1 image.png /folder2 Thanks! 回答1: Try something like this: var fs = require('fs'); var inStr = fs.createReadStream('/your/path/to/file'); var outStr = fs.createWriteStream('/your/path/to/destination'); inStr.pipe(outStr); Code is not tested, just written down from memory. 回答2: Or if you prefer callbacks: fs = require('fs') fs.readFile('folder1/image.png', function (err, data) { if (err) throw err; fs.writeFile('folder2

How to copy a image?

若如初见. 提交于 2020-06-24 10:14:29
问题 I want to copy image.png form /folder1 to /folder2 , how to do it? /folder1 image.png /folder2 Thanks! 回答1: Try something like this: var fs = require('fs'); var inStr = fs.createReadStream('/your/path/to/file'); var outStr = fs.createWriteStream('/your/path/to/destination'); inStr.pipe(outStr); Code is not tested, just written down from memory. 回答2: Or if you prefer callbacks: fs = require('fs') fs.readFile('folder1/image.png', function (err, data) { if (err) throw err; fs.writeFile('folder2

Replace a line in txt file using JavaScript

萝らか妹 提交于 2020-06-13 00:35:52
问题 I am trying to simply replace a line in a text file using JavaScript. The idea is: var oldLine = 'This is the old line'; var newLine = 'This new line replaces the old line'; Now i want to specify a file, find the oldLine and replace it with the newLine and save it. Anyone who can help me here? 回答1: This should do it var fs = require('fs') fs.readFile(someFile, 'utf8', function (err,data) { var formatted = data.replace(/This is the old line/g, 'This new line replaces the old line'); fs

Replace a line in txt file using JavaScript

耗尽温柔 提交于 2020-06-13 00:35:13
问题 I am trying to simply replace a line in a text file using JavaScript. The idea is: var oldLine = 'This is the old line'; var newLine = 'This new line replaces the old line'; Now i want to specify a file, find the oldLine and replace it with the newLine and save it. Anyone who can help me here? 回答1: This should do it var fs = require('fs') fs.readFile(someFile, 'utf8', function (err,data) { var formatted = data.replace(/This is the old line/g, 'This new line replaces the old line'); fs

Replace a line in txt file using JavaScript

匆匆过客 提交于 2020-06-13 00:35:12
问题 I am trying to simply replace a line in a text file using JavaScript. The idea is: var oldLine = 'This is the old line'; var newLine = 'This new line replaces the old line'; Now i want to specify a file, find the oldLine and replace it with the newLine and save it. Anyone who can help me here? 回答1: This should do it var fs = require('fs') fs.readFile(someFile, 'utf8', function (err,data) { var formatted = data.replace(/This is the old line/g, 'This new line replaces the old line'); fs