From the course: Learning Node.js

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Read from files

Read from files - Node.js Tutorial

From the course: Learning Node.js

Start my 1-month free trial

Read from files

(Male Narrator) - There are two areas where heavy input/output takes place. Network and disc access. So let's take a look at disk access to begin with by working with some files. We'll start with reading files and then move onto writing our own files. In order to do that we're going to require access to the file system that's built with the node. But first let's start by creating a new file. I'll call this demo.js. Now let's require in the file system and I'll call it fs for short. And as you can see, the library itself is also called fs. The next command we'll perform will be to read from the file but we don't have a file to read yet so let's create a temporary JSON file and put some data into it. I'll call it data.json and in here we'll simply create an object that has a property name. And we need to wrap the property in double quotes. Then I'll use a colon and I'll use the name Tim as a place holder. Let's close that out. The first thing we'll do is access the file system with a…

Contents