Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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 :: js string times 
Javascript :: javascript date to firebase timestamp 
Javascript :: get cookie in javascript 
Javascript :: scroll to div js 
Javascript :: javascript how to check if array is empty 
Javascript :: js get substring before character 
Javascript :: how to get url params value in node js 
Javascript :: regular expression to remove underscore from a string javascript 
Javascript :: javascript replace hyphen with space 
Javascript :: add value to each object in array javascript 
Javascript :: forloop in js 
Javascript :: react native strike through text 
Javascript :: javascript cors error 
Javascript :: what is cdn react 
Javascript :: js math.trunc 
Javascript :: extract payload of expired jwt token in js 
Javascript :: bs modal service close 
Javascript :: jquery insert after element 
Javascript :: ignore eslint warning one line 
Javascript :: change image src onclick javascript 
Javascript :: moment timezone set default timezone 
Javascript :: javascript string to lowercase 
Javascript :: js how to reverse a string 
Javascript :: countdown in react js 
Javascript :: datatables search not working 
Javascript :: what is computed in mobx 
Javascript :: how to hide title bar react-navigation 
Javascript :: jquery change tabs 
Javascript :: set default date today js 
Javascript :: how to add new key value to json object in javascript 
ADD CONTENT
Topic
Content
Source link
Name
1+7 =