How to Create Multiline Text File in Node.js?
Hi friends how to create multiline text file in node.js, how to create a multiline text file in node js, nodejs create a new multiline txt file with open, create multiline text file in node.js, create a multiline text file in node js example, how to make a multi-line text file in nodejs, node.js make new multiline text file example
In this tutorial, we shall learn to create multiline 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 multiline 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 multiline text file
var logger = fs.createWriteStream('readme.txt', {
flags: 'a' // 'a' means appending (old data will be preserved)
})
logger.write('Hi Nicesnippets.com! \n') // append string to your file
logger.write('This is body \n') // again
logger.write('Thank you') // again
Output:
It will create readme.txt file with following text.
Hi Nicesnippets.com!
This is body
Thank you
- How to Install Node Js and NPM Ubuntu?
- How to used Google ReCaptcha V3 in Node Js Express?
- How to Send Email with Attachment in Node js?
- How to Insert Data from Form into MySQL Database using Node js Express?
- Install Node Js and NPM Ubuntu 18.04/20.04/22.04 Tutorial
- How to Delete Data by id into MongoDB in Node JS?
- Install Node.js 16/17/18 on CentOS 8 Tutorial
- How to Upload File in MongoDB using Node js Express?