Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

fs.writefile

const fs = require('fs');

fs.writeFile("/tmp/test", "Hey there!", function(err) {
    if(err) {
        return console.log(err);
    }
    console.log("The file was saved!");
}); 

// Or
fs.writeFileSync('/tmp/test-sync', 'Hey there!');
Comment

nodejs: read and write file: use fs and promise

const { readFile, writeFile} = require('fs').promises;

const start = async () => {
    try {
        const first = await readFile('./content/first.txt', 'utf8');
        const second = await readFile('./content/second.txt', 'utf8');

        // Write file
        await writeFile('./content/result_mind_grenade.txt', `THIS IS AWESOME : ${first}  ${second}`, { flag: 'a' });
        
        console.log(first); 
        console.log(second);
    } catch (error) {
        console.log(error);
    }
}

start();

Comment

PREVIOUS NEXT
Code Example
Javascript :: react color picker 
Javascript :: dictionnary js 
Javascript :: regex in javascript 
Javascript :: jwt_access_secret generator 
Javascript :: jquery search string for substring 
Javascript :: angular cli command to create component without spec 
Javascript :: Remove uploaded file in jquery 
Javascript :: events js 
Javascript :: req.body showing undefined 
Javascript :: noise expression after effects 
Javascript :: url enocde in javascript 
Javascript :: mdn objects javascript 
Javascript :: react native android build location 
Javascript :: useThrottle 
Javascript :: truthy or falsy 
Javascript :: javascript Display Undeclared Variable 
Javascript :: javascript typeof operator returns function 
Javascript :: random number 1-3 
Javascript :: javascript even/uneven numbers 
Javascript :: lookup in other document in array 
Javascript :: prevent js execution in elementor 
Javascript :: change origin xy phaser 
Javascript :: phaser set alpha 
Javascript :: regular expression a-z and 0-9 
Javascript :: template literal inside a key in react 
Javascript :: nodejs mongodb native reuse single connection 
Javascript :: change on id 
Javascript :: javascript replace all with variable 
Javascript :: javascript trunc 
Javascript :: angular 9 features 
ADD CONTENT
Topic
Content
Source link
Name
3+2 =