Questions tagged [appendfile]

Use this tag for questions about asynchronously appending the given data to a file using a programing language (viz. Javascript).

It is most often used when someone wants to append content to file programmatically, such as using Javascript function fs.appendFile( path, data[, options], callback ), one can be able to asynchronously append the given data to a file. A new file is created if it does not exist. The options parameter can be used to modify the behavior of the operation.

e.g. Example in Node.JS

// Node.js program to demonstrate the 
// fs.appendFile() method 
  
// Import the filesystem module 
const fs = require('fs'); 
  
// Get the file contents before the append operation 
console.log("\nFile Contents of file before append:", 
  fs.readFileSync("example_file.txt", "utf8")); 
  
fs.appendFile("example_file.txt", "World", (err) => { 
  if (err) { 
    console.log(err); 
  } 
  else { 
    // Get the file contents after the append operation 
    console.log("\nFile Contents of file after append:", 
      fs.readFileSync("example_file.txt", "utf8")); 
  } 
}); 
27 questions
754
votes
18 answers

How to append to a file in Node?

I am trying to append a string to a log file. However writeFile will erase the content each time before writing the string. fs.writeFile('log.txt', 'Hello Node', function (err) { if (err) throw err; console.log('It\'s saved!'); }); // =>…
supercobra
  • 15,810
  • 9
  • 45
  • 51
12
votes
6 answers

Zend headScript() and appendFile not working as expected

I'm having an issue trying to append a javascript file using headScript()->appendFile('file name') with Zend. I have my layout setup like this: headScript() ->prependScript( 'BASE_URL = "' . $this->baseUrl() . '";' ) …
Ryan
  • 17,511
  • 23
  • 63
  • 88
5
votes
2 answers

Replace a line in txt file using JavaScript

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…
Wibo Kuipers
  • 83
  • 1
  • 2
  • 11
2
votes
1 answer

Append data to file with firefox extension

I'm trying to build a firefox extension and i want to write things periodically in a file. So i want a file in which i append new strings. The following code writes the file but at the end the file contains only the last string i wrote and not the…
John d.
  • 71
  • 5
2
votes
1 answer

NodeJS 'appendFile' not creating file in Docker container

I have an application that creates a few CSV files in its working directory while it runs. The application runs fine outside of my docker container, but when I run it within, I get an error: Error: ENOENT: no such file or directory, open…
Cerkoryn
  • 35
  • 5
2
votes
1 answer

Recombining large chunked zip download in GO

I am downloading a large .zip file in parallel with Accept-Ranges and Goroutines. The application sends multiple requests to download 10MB chunks of a zip file from a URL using its Range header. The requests get split up into different ranges as…
savidude
  • 73
  • 2
  • 11
1
vote
2 answers

How to generate an id when adding an object in node.js

I am trying to append an id to an object if it's the first and if there are others I want to add +1 to one that I am adding. I am using function that is called save and inside it there is a writeFile and an appendFile method: class Contenedor { …
1
vote
1 answer

How can I write every list from a nested list separately to a file?

I am trying to write every list from a nested list to the same file. However I want every list to start on a newline. I've made this and it works, but it's very inefficient and looks bad: appendFile "scraped.txt" (show (take 1 l)) appendFile…
1
vote
2 answers

write into json file with fs.append

I am working on a project using node.js and am struggling to fit an JSON object at the right position into my already existing data. My file currently looks like this: [ { "id": "001", "name": "Paul, "city": "London" }, { "id":…
Alex
  • 59
  • 8
1
vote
1 answer

NodeJs: fs.appendFile function seems to miss last String given

I'm new to nodejs I was trying the append function. When I run below code that simply takes User input after prompting him, about fav singer and puts in a file with singer name. And appending fav songs, It seems if user entered exit it should be…
1
vote
1 answer

Zend Framework - Include JS does not work on new System

I have a problem with ZF on my new server during JS file inclusions. Including external JS (google api) is no problem. It seems, that zf want to load the JS files not relative. The errormessage, displayed by FireBug in the Srcipt Tag of the html…
MCore
  • 11
  • 3
0
votes
0 answers

Merge text files in Sublime4 like append?

Yes, I want just combine files as simple as that: File1.txt line1 line2 line3 File2.txt line4 line5 line6 I want to open the above two files at once and receive File3.txt in a new tab like this line1 line2 line3 line4 line5 line6 It's odd that…
Suncatcher
  • 10,355
  • 10
  • 52
  • 90
0
votes
2 answers

how to log data into a new file?

I'm a beginner to node.js, started to learn just a few days ago. i'm trying to log the listener's data into a new file by using fs.appendFile, but no matter how many times i try to change the code, it keeps giving me an ERR-INVALID-CALLBACK. const…
eggyolk
  • 1
  • 1
0
votes
0 answers

Can I store all data in a single json file using fs.appendFileSync()?

I want to get multiple usernames and surnames with the form and store them all in a single user.json file. const express = require('express') const app = express() const fs = require('fs') const bodyparser =…
MRX yok
  • 31
  • 3
0
votes
0 answers

nodejs server restart and send the same request when calling appendfile

i am writing a program that send multiple request ti retrieve some data from an external api , it works fine , but when i try to add a function "appendFile" that save the data received in a json the server starts to behave strangely and restart…
justLearning
  • 59
  • 1
  • 7
1
2