Reading out the content in the file

The first step to print the title is to use a method we haven't used yet. We'll use the read method available on the filesystem module to read the contents. Let's make a variable called noteString. The noteString variable will be set equal to fs.readFileSync.

Now, readFileSync is similar to writeFileSync except that it doesn't take the text content, since it's getting the text content back for you. In this case, we'll just specify the first argument, which is the filename, notes.JSON:

var noteString = fs.readFileSync('notes.json');

Now that we have the string, it will be your job to take that string, use one of the preceding methods, and convert it back into an object. You can call that variable note. Next ...

Get Learning Node.js Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.