From the course: Node.js Essential Training

Unlock the full course today

Join today to access over 24,700 courses taught by industry experts.

Writing and appending files

Writing and appending files - Node.js Tutorial

From the course: Node.js Essential Training

Writing and appending files

- [Instructor] The fs module can also be used to write or append data to a file. In this lesson, we'll take a closer look. Let's create a new file here called writeFile and we're going to import the file system module, as you might expect. And then we're going to create some Markdown. So we're going to create a little template here. We'll say let md equal, we'll use a couple back ticks. And then within this, we'll say this is a New File. We'll underline this with equal signs for our header, and we'll say ES6 Template Strings are cool. They honor whitespace. And then we'll add some bullets here. So we'll say Template Strings, Node File System, and Readline CLIs. Cool. So now that I've created that, I can create a new file, and write the Markdown contents to this file. So we'll do this here on line 14 with fs.writeFile. Now, what writeFile is going to take in? It needs to take in the name of the new file. So…

Contents