Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

nodejs append to json

//Because we want JSON format to the file, we first need to read the file
//parse the data to JS object
//push the new items
//and then overwrite the file
var fs = require('fs')

var currentSearchResult = 'example'

fs.readFile('results.json', function (err, data) {
    var json = JSON.parse(data)
    json.push('search result: ' + currentSearchResult)

    fs.writeFile("results.json", JSON.stringify(json))
})
Comment

PREVIOUS NEXT
Code Example
Javascript :: Sum of Digits / Digital Root 
Javascript :: console.log() Print Values Stored in Variables 
Javascript :: vue compare two dates 
Javascript :: javascript remove css link 
Javascript :: check empty object javascript 
Javascript :: p5.js typescript 
Javascript :: how to install moralis and react-moralis 
Javascript :: use of map in react 
Javascript :: Using json_encode() function to convert an Array to a string 
Javascript :: getboundingclientrect 
Javascript :: js array remove undefined values 
Javascript :: c# convert object to json 
Javascript :: vue implode array 
Javascript :: javascript remove json element 
Javascript :: 2d array includes array js 
Javascript :: materialize dropdown js 
Javascript :: use filereader javascript 
Javascript :: closest js 
Javascript :: grid in chart.js 
Javascript :: how to check if a key is present in a dictionary in js 
Javascript :: how to make an array of a value from 1 to the number 
Javascript :: js number to str 
Javascript :: jsonb_set 
Javascript :: Using fetch to upload files 
Javascript :: proper to mixed fraction in javascript 
Javascript :: template literal syntax 
Javascript :: angular start command 
Javascript :: for...of Syntax 
Javascript :: js array 
Javascript :: vue style 
ADD CONTENT
Topic
Content
Source link
Name
2+2 =