From the course: Node.js Essential Training
Unlock the full course today
Join today to access over 24,800 courses taught by industry experts.
Using the require function - Node.js Tutorial
From the course: Node.js Essential Training
Using the require function
- So what else do we have globally available to us in Node.js? Well, we have some references to the current file and the current directory. So let's replace this with a few console.log messages. Remember, console.log is available to us globally without having to import anything. So we want to log the __dirname and the __filename. We also want to make sure that we're in the right folder. So we will make sure that we're navigated correctly, typing cd, dragging that file directory over. And then we're going to say node global. So now this is going to point directly at the directory where the file is located and then directly at the file. So notice that the filename variable includes the entire path. So also available to us globally is the common.js module pattern. So this is the pattern we're going to use to import other code into our files. One way that we can import these other modules is we can use this function.…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
Inspecting the global object3m 46s
-
(Locked)
Using the require function3m 4s
-
(Locked)
Handling argument variables with process.argv3m 29s
-
(Locked)
Working with standard input3m 37s
-
(Locked)
Using standard output3m 13s
-
(Locked)
Creating a delay with setTimeout2m 3s
-
(Locked)
Incorporating setInterval2m 51s
-
(Locked)
Reporting progress with setInterval1m 43s
-
-
-
-