fs

How to pipe multiple readable streams, from multiple api requests, to a single writeable stream?

此生再无相见时 提交于 2019-12-09 15:57:09
问题 - Desired Behaviour - Actual Behaviour - What I've Tried - Steps To Reproduce - Research Desired Behaviour Pipe multiple readable streams, received from multiple api requests, to a single writeable stream. The api responses are from ibm-watson's textToSpeech.synthesize() method. The reason multiple requests are required is because the service has a 5KB limit on text input. Therefore a string of 18KB , for example, requires four requests to complete. Actual Behaviour The writeable stream file

How to return a promise when writestream finishes? [duplicate]

天涯浪子 提交于 2019-12-09 13:31:55
问题 This question already has answers here : How do I convert an existing callback API to promises? (20 answers) Closed 3 years ago . I have such a function, which create a write stream and then write the string array into the file. I want to make it return a Promise once the writing is finished. But I don't know how I can make this work. function writeToFile(filePath: string, arr: string[]): Promise<boolean> { const file = fs.createWriteStream(filePath); arr.forEach(function(row) { file.write

How to read the content of files synchronously in Node.js?

此生再无相见时 提交于 2019-12-09 08:27:17
问题 This is what I have: #! /usr/bin/env node var fs = require('fs'), files = fs.readdirSync(__dirname + '/files/'), files.forEach(function(file) { fs.readFile(__dirname + '/files/' + file, 'utf8', function (error, data) { console.log(data) }) }) Even though I'm using readdirSync the output is still asynchronous: alex@alex-K43U:~/node/readFiles$ node index.js foo 1 foo 3 foo 2 How to modify the code so the output becomes synchronous? alex@alex-K43U:~/node/readFiles$ node index.js foo 1 foo 2 foo

Node.js: How to check if folder is empty or not with out uploading list of files

老子叫甜甜 提交于 2019-12-09 08:09:29
问题 I am using Node.js . I want to check if folder is empty or not? One option is to use fs.readdir but it loads whole bunch of files into an array. I have more than 10000 files in the folder. Loading files name is useless just to check if folder is empty or not. So looking for alternate solution. 回答1: How about using nodes native fs module http://nodejs.org/api/fs.html#fs_fs_readdir_path_callback. It's readdir and readdirSync functions provide you with an array of all the included file names

Angular 7 how to use fs module?

主宰稳场 提交于 2019-12-08 16:49:38
问题 I'm using Angular 7. I tried to use fs module on Typescript for open a directory. I always have this error: "Module not found: Error: Can't resolve fs" types@node and file-system are installed. My code: import {Component, OnInit} from '@angular/core'; import * as fs from 'file-system'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.scss'] }) export class AppComponent implements OnInit { title = 'my-app'; constructor() { } ngOnInit() {

Find String in a Txt File, Delete Entire Line

懵懂的女人 提交于 2019-12-08 16:01:22
问题 I'm currently working with node.js to create an IRC bot. The bot allows users to add song links to a database. Each time someone submits a song, it is added to a new line of "shuffle.txt" as such: user1,The Beatles,Yesterday,(youtube link) user2,The Rolling Stones,Angie,(youtube link) user1,The Bealtes,Yellow Sumbarine,(youtube link) Notice that user1 mistyped some information in their latest addition. I'm trying to make an UNDO command so that a user can delete their most recently entered

Cannot find module “fs”. Using simple-json-loader

流过昼夜 提交于 2019-12-08 07:19:17
问题 I'm try to use simple-json-loader . I install this from npm and write following function: onclickExport() { var loader = require('simple-json-loader'); var json = loader.JSONLoader.loadFromFile('wwwroot/dist/data/files.json'); } Еverything seems simple, but when I run build in webback i see following error: ERROR in ./~/simple-json-loader/index.js Module not found: Error: Cannot resolve module 'fs' in D:\GitRepo\Magazine\Magazine.Web\node_modules\simple-json-loader @ ./~/simple-json-loader

Allow user to download file from public folder Meteor.js

雨燕双飞 提交于 2019-12-08 05:46:00
问题 I am generating a .xlsx file and then place it into "../web.browser/app/cheques.xlsx" . As I understand it is an equivalent of public folder inside the build. The problem is that I can't manage to make it available for download. This is a fragment of code in server method, where I place a file into that place: workbook.xlsx.writeFile("../web.browser/app/cheques.xlsx") .then(function() { console.log('done'); }); So should I use fs or Picker.route to do the job? 回答1: It's not advisable to do

Watching for file changes on complete file transfer

烂漫一生 提交于 2019-12-08 01:04:43
问题 I have a simple node script that looks for a file changes and copies file to the remote server using ssh. fs.watch(filename,function(curr,prev){ //copy file to the remote server }); However, since the file i'm watching is uploaded via ftp and for every chunk of data i recieve the file gets changed and the callback gets fired. Is there any way to look for changes only when the complete file has been transfered? Thanks in advance. 回答1: I know this is an old question but for anyone else in the

Sending response after forEach

我与影子孤独终老i 提交于 2019-12-07 21:52:48
问题 (Please note this is not a duplicate of two similarly titled questions, those two questions use Mongoose and the answers apply to Mongoose queries only) I have a list of directories, each of these directories contains a file. I want to return a JSON list with the contents of each of these files. I can load the files no problem, but because I'm looping over the array with forEach , my empty response is sent before I've actually loaded the contents of the files: function getInputDirectories() {