nodejs file system access

Learn to use nodejs to access the file system, reading and writing files.

First we’ll need to import the file system functions with require(“fs”);

Next, we’ll use that handle to read in the notes.txt file. That will either return data, or err if there’s an error.

Next we’re simply returning the text of the file to the console. That’s it! Awesomeness.

How about writing files you say? Let’s do it!

Again we start off by importing the file handling functions, creating a file handle and declare the location of the file we want to use. Unlike other programming languages, nodejs is smart enough to create the file even though it doesn’t exist yet.