Node.js allows you to read files with the fs module. You can read the contents of a file encoded in a certain format. In this video, learn how to read files, dealing with synchronous and asynchronous file reading. Also, learn how to read files of many types by matching with regular expression patterns in this video.
- [Instructor] We can also use the FS Module … to read the contents of a file. … Let's go into our start folder and … create a new file called readfile.js. … And within the readfile.js we're also … going to use the FS module so the first thing … that I'm going to do is require that module. … And then I'm going to go ahead and read … the text that's located in one of our assets. … So I'm going to read the text from … the readme.md file, there's just … some text as we can see here, so … I'm going to go back to read file and … I'm going to fs.readFileSync, so … we're going to do this first synchronously … which means that this is going to be blocking. … We're going to wait until we've read the contents … of the entire file before executing any more code … so we'll read it in assets/Readme.md. … The second argument that I want to supply … is the encoding of a file, since this is … a text file, we're going to read this as UTF-8. … So now I can go ahead and console.log text … then I can open up our terminal and …
- What is Node.js?
- Installing Node.js
- The global object
- Importing the core modules
- Creating custom events with the EventEmitter
- Reading, writing, and removing files
- Working with file streams
- Creating child processes with the exec and spawn functions
Skill Level Intermediate
Node.js: Real-Time Web with Socket.IOwith Emmanuel Henri1h 24m Intermediate
1. What Is Node.js?
2. Set Up Your Environnment
3. Node Globals
4. Node Modules
5. File System Basics
6. Files and Streams
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.