26-Aug-2022
.
Admin
Hi friends
This tutorial is focused on how to create an empty text file in node.js. you will learn how to create an empty text file in nodejs. you can see that nodejs create the empty text file. you will learn node.js to create an empty text file. So, let's follow a few step to create an example of create an empty text file in node.js.
In this tutorial, we shall learn to create empty text File in Node.js using Node FS (File System) built-in module. Node.js example programs that use fs.createWriteStream() function are provided. So, let's follow a few step to create an example of node js create an empty text file example.
Let's see below simple example with output:
Step 1: Create Node.js Project
This step is not required; however, if you have not created the node js app, then you may go ahead and execute the below command:
mkdir my-app
cd my-app
npm init
Step 2: Update server.js File
server.js
//require fs (File System) create file
fs = require('fs')
// create empty file
logger = fs.createWriteStream('empty.txt', {
flags: 'a'
})
console.log('New empty text file created successfully!');
Output:
New empty text file created successfully!
Create empty new file name:
empty.txt
#Node JS