Join Alexander Zanfir for an in-depth discussion in this video Writing to files, part of Learning Node.js (2015).
- Since we know how to read files and read directories,…next let's move on to writing our own files.…As usual, we'll begin by creating a new file.…We'll call this writefiledemo.js…and we'll require in the file system.…And you probably guessed it,…in order to write a file,…we're going to access the file system…and use the function writeFile,…with an upper case F.…The first parameter is the name of the file,…and we'll be writing a json file,…so let's call it maybe tom.json,…since we want to store the name of the user in there.…
And the second parameter is the actual data…that will be written to the file.…So we could have it in line,…but I'm going to create a variable for that.…So let's call it tomString,…since it has to be in the String format.…And by that I mean we can't actually pass an adjacent object…as a second parameter to write file.…Let's see what happens when we try to do that.…So I'll create our tomString,…but for this demo I'm just going to set it to an object.…
And let's run that.…And now if we refresh,…
- Installing Node.js
- Writing modules and packages
- Reading and writing files
- Working with frameworks: Express, Sails, and Koa
- Generating promises
- Working with generator functions
Skill Level Beginner
Q: When I try to install Bluebird/Express/Gulp/Sails/KOA using the Node Package Manager, it seems to install correctly in the terminal. But why doesn't my project folder change?
A: You need to make sure that you've navigated to your project folder in the terminal. For example, in this course Alexander is working from the C:\Dev\ folder both in Brackets and in the terminal.