Second part:
3 Pretty Cool Built-In Node.js Modules
Let’s read user input, execute terminal commands & run a virtual machine for JS — using Node.js!
medium.com
What Are Built-In Modules?
Node.js has some so-called built-in modules. This means that although these modules work like other modules that we can install, e.g., via npm and then include using the require
or import
syntax, as the name suggests, built-in modules are already installed and, therefore, always available.
And of course, they are maintained by the development team behind Node.js, so everything is always up to date and we can use the modules without worries.
Features of the modules that are deprecated can be recognized as such in the official documentation.
So, all good reasons to have a look at some of these modules and to use them in our next project.
1. Performance Timing API (perf_hooks)
In this module, we are provided with various features to examine the performance of our Node.js app.
The API, which is also implemented in modern browsers, provides very precise results and is therefore perfectly suited to be the first choice for analyzing your own app.
Let’s take a look at an example where we examine the time it takes to read a large file and compare it to reading a small file. The large file contains about 3000 lines of Lorem Ipsum, the small file only 20 lines of Lorem Ipsum.
If you run the Node app a few times, you should see that it takes on average much longer to read the large file with the readFileSync
function.
https://sv.tie.org/sv/nfl/Cha-den-Rams-v-Seahawks-cbn-00.html
https://sv.tie.org/sv/nfl/Cha-den-Rams-v-Seahawks-cbn-01.html
https://sv.tie.org/sv/nfl/Cha-den-Rams-v-Seahawks-cbn-02.html
https://sv.tie.org/sv/nfl/Cha-den-Rams-v-Seahawks-cbn-03.html
https://sv.tie.org/sv/nfl/Cha-den-Saints-v-49ers-cbn-00.html
https://sv.tie.org/sv/nfl/Cha-den-Saints-v-49ers-cbn-01.html
https://sv.tie.org/sv/nfl/Cha-den-Saints-v-49ers-cbn-02.html
https://sv.tie.org/sv/nfl/Cha-den-Saints-v-49ers-cbn-03.html
https://sv.tie.org/sv/nfl/Cha-den-Steelers-v-Bengals-cbn-00.html
https://sv.tie.org/sv/nfl/Cha-den-Steelers-v-Bengals-cbn-01.html
https://sv.tie.org/sv/nfl/Cha-den-Steelers-v-Bengals-cbn-02.html
https://sv.tie.org/sv/nfl/Cha-den-Steelers-v-Bengals-cbn-03.html
https://sv.tie.org/sv/nfl/Jonny-Bills-v-Cardinals-cbn-00.html
https://sv.tie.org/sv/nfl/Jonny-Bills-v-Cardinals-cbn-01.html
https://sv.tie.org/sv/nfl/Jonny-Bills-v-Cardinals-cbn-02.html
https://sv.tie.org/sv/nfl/Jonny-Bills-v-Cardinals-cbn-03.html
https://sv.tie.org/sv/nfl/pori-moni-Dolphins-Chargers-cbn-00.html
https://sv.tie.org/sv/nfl/pori-moni-Dolphins-Chargers-cbn-01.html
https://sv.tie.org/sv/nfl/pori-moni-Dolphins-Chargers-cbn-02.html
https://sv.tie.org/sv/nfl/pori-moni-Dolphins-Chargers-cbn-03.html
https://sv.tie.org/sv/nfl/pori-Raiders-Broncos-cbn-00.html
https://sv.tie.org/sv/nfl/pori-Raiders-Broncos-cbn-01.html
https://sv.tie.org/sv/nfl/pori-Raiders-Broncos-cbn-02.html
https://sv.tie.org/sv/nfl/pori-Raiders-Broncos-cbn-03.html
https://www.jaguar.gi/jag/Cha-den-Rams-v-Seahawks-cbn-00.html
https://www.jaguar.gi/jag/Cha-den-Rams-v-Seahawks-cbn-01.html
https://www.jaguar.gi/jag/Cha-den-Rams-v-Seahawks-cbn-02.html
https://www.jaguar.gi/jag/Cha-den-Rams-v-Seahawks-cbn-03.html
https://www.jaguar.gi/jag/Cha-den-Saints-v-49ers-cbn-00.html
https://www.jaguar.gi/jag/Cha-den-Saints-v-49ers-cbn-01.html
https://www.jaguar.gi/jag/Cha-den-Saints-v-49ers-cbn-02.html
https://www.jaguar.gi/jag/Cha-den-Saints-v-49ers-cbn-03.html
https://www.jaguar.gi/jag/Cha-den-Steelers-v-Bengals-cbn-00.html
https://www.jaguar.gi/jag/Cha-den-Steelers-v-Bengals-cbn-01.html
https://www.jaguar.gi/jag/Cha-den-Steelers-v-Bengals-cbn-02.html
https://www.jaguar.gi/jag/Cha-den-Steelers-v-Bengals-cbn-03.html
http://landrover.gi/land/us/Cha-den-Rams-v-Seahawks-cbn-00.html
http://landrover.gi/land/us/Cha-den-Rams-v-Seahawks-cbn-01.html
http://landrover.gi/land/us/Cha-den-Rams-v-Seahawks-cbn-02.html
http://landrover.gi/land/us/Cha-den-Rams-v-Seahawks-cbn-03.html
http://landrover.gi/land/us/Cha-den-Saints-v-49ers-cbn-00.html
http://landrover.gi/land/us/Cha-den-Saints-v-49ers-cbn-01.html
http://landrover.gi/land/us/Cha-den-Saints-v-49ers-cbn-02.html
http://landrover.gi/land/us/Cha-den-Saints-v-49ers-cbn-03.html
http://landrover.gi/land/us/Cha-den-Steelers-v-Bengals-cbn-00.html
http://landrover.gi/land/us/Cha-den-Steelers-v-Bengals-cbn-01.html
http://landrover.gi/land/us/Cha-den-Steelers-v-Bengals-cbn-02.html
http://landrover.gi/land/us/Cha-den-Steelers-v-Bengals-cbn-03.html
https://ayf.com/eox/Cha-den-Rams-v-Seahawks-cbn-00.html
https://ayf.com/eox/Cha-den-Rams-v-Seahawks-cbn-01.html
https://ayf.com/eox/Cha-den-Rams-v-Seahawks-cbn-02.html
https://ayf.com/eox/Cha-den-Rams-v-Seahawks-cbn-03.html
https://ayf.com/eox/Cha-den-Saints-v-49ers-cbn-00.html
https://ayf.com/eox/Cha-den-Saints-v-49ers-cbn-01.html
https://ayf.com/eox/Cha-den-Saints-v-49ers-cbn-02.html
https://ayf.com/eox/Cha-den-Saints-v-49ers-cbn-03.html
https://ayf.com/eox/Cha-den-Steelers-v-Bengals-cbn-00.html
https://ayf.com/eox/Cha-den-Steelers-v-Bengals-cbn-01.html
https://ayf.com/eox/Cha-den-Steelers-v-Bengals-cbn-02.html
https://ayf.com/eox/Cha-den-Steelers-v-Bengals-cbn-03.html
https://www.jaguar.gi/jag/BR-Broncos-v-Raiders-liv-hd-tv-nfl00.html
https://www.jaguar.gi/jag/BR-Broncos-v-Raiders-liv-hd-tv-nfl01.html
https://www.jaguar.gi/jag/BR-Broncos-v-Raiders-liv-hd-tv-nfl02.html
https://www.jaguar.gi/jag/BR-Broncos-v-Raiders-liv-hd-tv-nfl03.html
https://www.jaguar.gi/jag/BR-Broncos-v-Raiders-liv-hd-tv-nfl04.html
https://www.jaguar.gi/jag/BR-Broncos-v-Raiders-liv-hd-tv-nfl05.html
https://www.jaguar.gi/jag/BR-Broncos-v-Raiders-liv-hd-tv-nfl06.html
https://www.jaguar.gi/jag/BR-Broncos-v-Raiders-liv-hd-tv-nfl07.html
https://www.jaguar.gi/jag/BR-Broncos-v-Raiders-liv-hd-tv-nfl08.html
https://www.jaguar.gi/jag/Cd-Chargers-v-Dolphins-liv-ontv-21.html
https://www.jaguar.gi/jag/Cd-Chargers-v-Dolphins-liv-ontv-22.html
https://www.jaguar.gi/jag/Cd-Chargers-v-Dolphins-liv-ontv-23.html
https://www.jaguar.gi/jag/Cd-Chargers-v-Dolphins-liv-ontv-24.html
https://www.jaguar.gi/jag/Cd-Chargers-v-Dolphins-liv-ontv-25.html
https://www.jaguar.gi/jag/Cd-Chargers-v-Dolphins-liv-ontv-26.html
https://www.jaguar.gi/jag/Cd-Chargers-v-Dolphins-liv-ontv-27.html
http://landrover.gi/land/us/Rs-Seahawks-v-Rams-liv-op-tvc-co-1.html
http://landrover.gi/land/us/Rs-Seahawks-v-Rams-liv-op-tvc-co-2.html
http://landrover.gi/land/us/Rs-Seahawks-v-Rams-liv-op-tvc-co-3.html
http://landrover.gi/land/us/Rs-Seahawks-v-Rams-liv-op-tvc-co-4.html
http://landrover.gi/land/us/Rs-Seahawks-v-Rams-liv-op-tvc-co-5.html
http://landrover.gi/land/us/Rs-Seahawks-v-Rams-liv-op-tvc-co-6.html
http://landrover.gi/land/us/Rs-Seahawks-v-Rams-liv-op-tvc-co-7.html
http://landrover.gi/land/us/Rs-Seahawks-v-Rams-liv-op-tvc-co-8.html
http://landrover.gi/land/us/S-49ers-v-Saints-liv-hq-tv-81.html
http://landrover.gi/land/us/S-49ers-v-Saints-liv-hq-tv-82.html
http://landrover.gi/land/us/S-49ers-v-Saints-liv-hq-tv-83.html
http://landrover.gi/land/us/S-49ers-v-Saints-liv-hq-tv-84.html
http://landrover.gi/land/us/S-49ers-v-Saints-liv-hq-tv-85.html
http://landrover.gi/land/us/S-49ers-v-Saints-liv-hq-tv-86.html
http://landrover.gi/land/us/S-49ers-v-Saints-liv-hq-tv-87.html
http://landrover.gi/land/us/S-49ers-v-Saints-liv-hq-tv-88.html
https://www.jaguar.gi/jag/Rs-Seahawks-v-Rams-liv-op-tvc-co-1.html
https://www.jaguar.gi/jag/Rs-Seahawks-v-Rams-liv-op-tvc-co-2.html
https://www.jaguar.gi/jag/Rs-Seahawks-v-Rams-liv-op-tvc-co-3.html
https://www.jaguar.gi/jag/Rs-Seahawks-v-Rams-liv-op-tvc-co-4.html
https://www.jaguar.gi/jag/Rs-Seahawks-v-Rams-liv-op-tvc-co-5.html
https://www.jaguar.gi/jag/Rs-Seahawks-v-Rams-liv-op-tvc-co-6.html
https://www.jaguar.gi/jag/Rs-Seahawks-v-Rams-liv-op-tvc-co-7.html
https://www.jaguar.gi/jag/Rs-Seahawks-v-Rams-liv-op-tvc-co-8.html
https://www.jaguar.gi/jag/S-49ers-v-Saints-liv-hq-tv-81.html
https://www.jaguar.gi/jag/S-49ers-v-Saints-liv-hq-tv-82.html
https://www.jaguar.gi/jag/S-49ers-v-Saints-liv-hq-tv-83.html
https://www.jaguar.gi/jag/S-49ers-v-Saints-liv-hq-tv-84.html
https://www.jaguar.gi/jag/S-49ers-v-Saints-liv-hq-tv-85.html
https://www.jaguar.gi/jag/S-49ers-v-Saints-liv-hq-tv-86.html
https://www.jaguar.gi/jag/S-49ers-v-Saints-liv-hq-tv-87.html
https://www.jaguar.gi/jag/S-49ers-v-Saints-liv-hq-tv-88.html
http://landrover.gi/land/us/BR-Broncos-v-Raiders-liv-hd-tv-nfl00.html
http://landrover.gi/land/us/BR-Broncos-v-Raiders-liv-hd-tv-nfl01.html
http://landrover.gi/land/us/BR-Broncos-v-Raiders-liv-hd-tv-nfl02.html
http://landrover.gi/land/us/BR-Broncos-v-Raiders-liv-hd-tv-nfl03.html
http://landrover.gi/land/us/BR-Broncos-v-Raiders-liv-hd-tv-nfl04.html
http://landrover.gi/land/us/BR-Broncos-v-Raiders-liv-hd-tv-nfl05.html
http://landrover.gi/land/us/BR-Broncos-v-Raiders-liv-hd-tv-nfl06.html
http://landrover.gi/land/us/BR-Broncos-v-Raiders-liv-hd-tv-nfl07.html
http://landrover.gi/land/us/BR-Broncos-v-Raiders-liv-hd-tv-nfl08.html
http://landrover.gi/land/us/Cd-Chargers-v-Dolphins-liv-ontv-21.html
http://landrover.gi/land/us/Cd-Chargers-v-Dolphins-liv-ontv-22.html
http://landrover.gi/land/us/Cd-Chargers-v-Dolphins-liv-ontv-23.html
http://landrover.gi/land/us/Cd-Chargers-v-Dolphins-liv-ontv-24.html
http://landrover.gi/land/us/Cd-Chargers-v-Dolphins-liv-ontv-25.html
http://landrover.gi/land/us/Cd-Chargers-v-Dolphins-liv-ontv-26.html
http://landrover.gi/land/us/Cd-Chargers-v-Dolphins-liv-ontv-27.html
https://www.jaguar.gi/jag/3Up-Chargers-v-Dolphins-liv-Cc00.html
https://www.jaguar.gi/jag/3Up-Chargers-v-Dolphins-liv-Cc01.html
https://www.jaguar.gi/jag/3Up-Chargers-v-Dolphins-liv-Cc02.html
https://www.jaguar.gi/jag/3Up-Chargers-v-Dolphins-liv-Cc03.html
https://www.jaguar.gi/jag/3Up-Chargers-v-Dolphins-liv-Cc04.html
https://www.jaguar.gi/jag/3Up-Chargers-v-Dolphins-liv-Cc05.html
https://www.jaguar.gi/jag/3Up-Chargers-v-Dolphins-liv-Cc06.html
http://landrover.gi/land/us/3Up-Chargers-v-Dolphins-liv-Cc00.html
http://landrover.gi/land/us/3Up-Chargers-v-Dolphins-liv-Cc01.html
http://landrover.gi/land/us/3Up-Chargers-v-Dolphins-liv-Cc02.html
http://landrover.gi/land/us/3Up-Chargers-v-Dolphins-liv-Cc03.html
http://landrover.gi/land/us/3Up-Chargers-v-Dolphins-liv-Cc04.html
http://landrover.gi/land/us/3Up-Chargers-v-Dolphins-liv-Cc05.html
http://landrover.gi/land/us/3Up-Chargers-v-Dolphins-liv-Cc06.html
https://ayf.com/eox/3Up-Chargers-v-Dolphins-liv-Cc00.html
https://ayf.com/eox/3Up-Chargers-v-Dolphins-liv-Cc01.html
https://ayf.com/eox/3Up-Chargers-v-Dolphins-liv-Cc02.html
https://ayf.com/eox/3Up-Chargers-v-Dolphins-liv-Cc03.html
https://ayf.com/eox/3Up-Chargers-v-Dolphins-liv-Cc04.html
https://ayf.com/eox/3Up-Chargers-v-Dolphins-liv-Cc05.html
https://ayf.com/eox/3Up-Chargers-v-Dolphins-liv-Cc06.html
https://www.jaguar.gi/jag/4Up-Broncos-v-Raiders-liv-Ee00.html
https://www.jaguar.gi/jag/4Up-Broncos-v-Raiders-liv-Ee01.html
https://www.jaguar.gi/jag/4Up-Broncos-v-Raiders-liv-Ee02.html
https://www.jaguar.gi/jag/4Up-Broncos-v-Raiders-liv-Ee03.html
https://www.jaguar.gi/jag/4Up-Broncos-v-Raiders-liv-Ee04.html
https://www.jaguar.gi/jag/4Up-Broncos-v-Raiders-liv-Ee05.html
https://www.jaguar.gi/jag/4Up-Broncos-v-Raiders-liv-Ee06.html
http://landrover.gi/land/us/4Up-Broncos-v-Raiders-liv-Ee00.html
http://landrover.gi/land/us/4Up-Broncos-v-Raiders-liv-Ee01.html
http://landrover.gi/land/us/4Up-Broncos-v-Raiders-liv-Ee02.html
http://landrover.gi/land/us/4Up-Broncos-v-Raiders-liv-Ee03.html
http://landrover.gi/land/us/4Up-Broncos-v-Raiders-liv-Ee04.html
http://landrover.gi/land/us/4Up-Broncos-v-Raiders-liv-Ee05.html
http://landrover.gi/land/us/4Up-Broncos-v-Raiders-liv-Ee06.html
https://ayf.com/eox/4Up-Broncos-v-Raiders-liv-Ee00.html
https://ayf.com/eox/4Up-Broncos-v-Raiders-liv-Ee01.html
https://ayf.com/eox/4Up-Broncos-v-Raiders-liv-Ee02.html
https://ayf.com/eox/4Up-Broncos-v-Raiders-liv-Ee03.html
https://ayf.com/eox/4Up-Broncos-v-Raiders-liv-Ee04.html
https://ayf.com/eox/4Up-Broncos-v-Raiders-liv-Ee05.html
https://ayf.com/eox/4Up-Broncos-v-Raiders-liv-Ee06.html
https://www.jaguar.gi/jag/5Up-Seahawks-v-Rams-liv-Fc00.html
https://www.jaguar.gi/jag/5Up-Seahawks-v-Rams-liv-Fc01.html
https://www.jaguar.gi/jag/5Up-Seahawks-v-Rams-liv-Fc02.html
https://www.jaguar.gi/jag/5Up-Seahawks-v-Rams-liv-Fc03.html
https://www.jaguar.gi/jag/5Up-Seahawks-v-Rams-liv-Fc04.html
https://www.jaguar.gi/jag/5Up-Seahawks-v-Rams-liv-Fc05.html
https://www.jaguar.gi/jag/5Up-Seahawks-v-Rams-liv-Fc06.html
http://landrover.gi/land/us/5Up-Seahawks-v-Rams-liv-Fc00.html
http://landrover.gi/land/us/5Up-Seahawks-v-Rams-liv-Fc01.html
http://landrover.gi/land/us/5Up-Seahawks-v-Rams-liv-Fc02.html
http://landrover.gi/land/us/5Up-Seahawks-v-Rams-liv-Fc03.html
http://landrover.gi/land/us/5Up-Seahawks-v-Rams-liv-Fc04.html
http://landrover.gi/land/us/5Up-Seahawks-v-Rams-liv-Fc05.html
http://landrover.gi/land/us/5Up-Seahawks-v-Rams-liv-Fc06.html
https://ayf.com/eox/5Up-Seahawks-v-Rams-liv-Fc00.html
https://ayf.com/eox/5Up-Seahawks-v-Rams-liv-Fc01.html
https://ayf.com/eox/5Up-Seahawks-v-Rams-liv-Fc02.html
https://ayf.com/eox/5Up-Seahawks-v-Rams-liv-Fc03.html
https://ayf.com/eox/5Up-Seahawks-v-Rams-liv-Fc04.html
https://ayf.com/eox/5Up-Seahawks-v-Rams-liv-Fc05.html
https://ayf.com/eox/5Up-Seahawks-v-Rams-liv-Fc06.html
https://www.jaguar.gi/jag/6p-49ers-v-Saints-liv-Mm00.html
https://www.jaguar.gi/jag/6p-49ers-v-Saints-liv-Mm01.html
https://www.jaguar.gi/jag/6p-49ers-v-Saints-liv-Mm02.html
https://www.jaguar.gi/jag/6p-49ers-v-Saints-liv-Mm03.html
https://www.jaguar.gi/jag/6p-49ers-v-Saints-liv-Mm04.html
https://www.jaguar.gi/jag/6p-49ers-v-Saints-liv-Mm05.html
https://www.jaguar.gi/jag/6p-49ers-v-Saints-liv-Mm06.html
http://landrover.gi/land/us/6p-49ers-v-Saints-liv-Mm00.html
http://landrover.gi/land/us/6p-49ers-v-Saints-liv-Mm01.html
http://landrover.gi/land/us/6p-49ers-v-Saints-liv-Mm02.html
http://landrover.gi/land/us/6p-49ers-v-Saints-liv-Mm03.html
http://landrover.gi/land/us/6p-49ers-v-Saints-liv-Mm04.html
http://landrover.gi/land/us/6p-49ers-v-Saints-liv-Mm05.html
http://landrover.gi/land/us/6p-49ers-v-Saints-liv-Mm06.html
https://ayf.com/eox/6p-49ers-v-Saints-liv-Mm00.html
https://ayf.com/eox/6p-49ers-v-Saints-liv-Mm01.html
https://ayf.com/eox/6p-49ers-v-Saints-liv-Mm02.html
https://ayf.com/eox/6p-49ers-v-Saints-liv-Mm03.html
https://ayf.com/eox/6p-49ers-v-Saints-liv-Mm04.html
https://ayf.com/eox/6p-49ers-v-Saints-liv-Mm05.html
https://ayf.com/eox/6p-49ers-v-Saints-liv-Mm06.html
https://www.jaguar.gi/jag/video-Broncos-v-tvbb01.html
https://www.jaguar.gi/jag/video-Broncos-v-tvbb02.html
https://www.jaguar.gi/jag/video-Broncos-v-tvbb03.html
https://www.jaguar.gi/jag/video-Broncos-v-tvbb04.html
https://www.jaguar.gi/jag/video-Broncos-v-tvbb05.html
https://www.jaguar.gi/jag/video-Broncos-v-tvbb06.html
https://www.jaguar.gi/jag/video-Broncos-v-tvbb07.html
https://www.jaguar.gi/jag/video-Broncos-v-tvbb08.html
https://sv.tie.org/sv/nfl/1Up-Bills-v-Cardinals-liv-xx00.html
https://sv.tie.org/sv/nfl/1Up-Bills-v-Cardinals-liv-xx01.html
https://sv.tie.org/sv/nfl/1Up-Bills-v-Cardinals-liv-xx02.html
https://sv.tie.org/sv/nfl/1Up-Bills-v-Cardinals-liv-xx03.html
https://sv.tie.org/sv/nfl/1Up-Bills-v-Cardinals-liv-xx04.html
https://sv.tie.org/sv/nfl/1Up-Bills-v-Cardinals-liv-xx05.html
https://sv.tie.org/sv/nfl/1Up-Bills-v-Cardinals-liv-xx06.html
https://sv.tie.org/sv/nfl/2Up-Bengals-v-Steelers-liv-xx00.html
https://sv.tie.org/sv/nfl/2Up-Bengals-v-Steelers-liv-xx01.html
https://sv.tie.org/sv/nfl/2Up-Bengals-v-Steelers-liv-xx02.html
https://sv.tie.org/sv/nfl/2Up-Bengals-v-Steelers-liv-xx03.html
https://sv.tie.org/sv/nfl/2Up-Bengals-v-Steelers-liv-xx04.html
https://sv.tie.org/sv/nfl/2Up-Bengals-v-Steelers-liv-xx05.html
https://sv.tie.org/sv/nfl/2Up-Bengals-v-Steelers-liv-xx06.html
https://sv.tie.org/sv/nfl/3Up-Chargers-v-Dolphins-liv-Cc00.html
https://sv.tie.org/sv/nfl/3Up-Chargers-v-Dolphins-liv-Cc01.html
https://sv.tie.org/sv/nfl/3Up-Chargers-v-Dolphins-liv-Cc02.html
https://sv.tie.org/sv/nfl/3Up-Chargers-v-Dolphins-liv-Cc03.html
https://sv.tie.org/sv/nfl/3Up-Chargers-v-Dolphins-liv-Cc04.html
https://sv.tie.org/sv/nfl/3Up-Chargers-v-Dolphins-liv-Cc05.html
https://sv.tie.org/sv/nfl/3Up-Chargers-v-Dolphins-liv-Cc06.html
https://sv.tie.org/sv/nfl/4Up-Broncos-v-Raiders-liv-Ee00.html
https://sv.tie.org/sv/nfl/4Up-Broncos-v-Raiders-liv-Ee01.html
https://sv.tie.org/sv/nfl/4Up-Broncos-v-Raiders-liv-Ee02.html
https://sv.tie.org/sv/nfl/4Up-Broncos-v-Raiders-liv-Ee03.html
https://sv.tie.org/sv/nfl/4Up-Broncos-v-Raiders-liv-Ee04.html
https://sv.tie.org/sv/nfl/4Up-Broncos-v-Raiders-liv-Ee05.html
https://sv.tie.org/sv/nfl/4Up-Broncos-v-Raiders-liv-Ee06.html
https://sv.tie.org/sv/nfl/5Up-Seahawks-v-Rams-liv-Fc00.html
https://sv.tie.org/sv/nfl/5Up-Seahawks-v-Rams-liv-Fc01.html
https://sv.tie.org/sv/nfl/5Up-Seahawks-v-Rams-liv-Fc02.html
https://sv.tie.org/sv/nfl/5Up-Seahawks-v-Rams-liv-Fc03.html
https://sv.tie.org/sv/nfl/5Up-Seahawks-v-Rams-liv-Fc04.html
https://sv.tie.org/sv/nfl/5Up-Seahawks-v-Rams-liv-Fc05.html
https://sv.tie.org/sv/nfl/5Up-Seahawks-v-Rams-liv-Fc06.html
https://sv.tie.org/sv/nfl/6p-49ers-v-Saints-liv-Mm00.html
https://sv.tie.org/sv/nfl/6p-49ers-v-Saints-liv-Mm01.html
https://sv.tie.org/sv/nfl/6p-49ers-v-Saints-liv-Mm02.html
https://sv.tie.org/sv/nfl/6p-49ers-v-Saints-liv-Mm03.html
https://sv.tie.org/sv/nfl/6p-49ers-v-Saints-liv-Mm04.html
https://sv.tie.org/sv/nfl/6p-49ers-v-Saints-liv-Mm05.html
https://sv.tie.org/sv/nfl/6p-49ers-v-Saints-liv-Mm06.html
Our Node app to measure the reading duration
We use the performance.mark
functions for this purpose by surrounding the actual code whose execution we want to examine with these markers.
So, we always set a start and an endpoint, and with the performance.measure
function, we can then store the whole thing in the performance timeline so that we can give out the results with the PerformanceObserver
.
The first parameter of the measure function is just the name, the other two are the names of the start and endpoints.
The results should look like this:
Of course, the times will depend on your machine.
2. The File System Module (fs)
I think everyone already knows the fs
module, which stands for file system, and allows access to the file system. As the name says.
Most of you should already know it from when you first used Node.js, and the basic functions of fs
modules work similarly in almost all programming languages.
But there are some cool features that are not so well-known, which I will introduce to you now.
Check whether it is a folder
const fs = require(‘fs’)// will return false, no directory
fs.statSync(‘./index.html’).isDirectory()
Print all the files in a directory
fs.readdir(‘./test-dir’, (err, files) => {
files.forEach(file => {
console.log(file)
})
})
Watch a directory for changes and give out the type of change
fs.watch(‘./test-dir’, (eventType, filename) => {
if (filename) console.log(filename, eventType)
})
The basic features of the fs module
Read the file and print out the content of it
fs.readFile(‘./note.txt’, ‘utf8’, (err, data) => {
console.log(data)
})
If you leave out the parameter for the decoding, in our example, “utf8
”, by default, the content will be given out as a buffer.
Add something to the file
fs.appendFile(‘./note.txt’, ‘This is new!’, err => {
if (err) throw err
console.log(‘file changed’)
})
Create a new file, write something into it/clear file
fs.writeFile(‘./note.txt’, ‘’, err => {
if (err) throw err
console.log(‘file cleared’)
})
The second parameter of this function is the content that should be written to the file. In our example, we left this empty so if the given file exists, it will be made completely empty.
If it does not exist, it will be created, but will also remain empty. So, this function is not suitable for adding content to files, because it overwrites everything that has been added before.
3. The Operating System Module (os)
This module can output all kinds of information about the system on which Node.js is currently running. For example, it can be used to monitor the performance of a server.
Here are a few useful functions whose output I have converted directly so that they are more understandable for us.
By dividing the value for os.totalmem()
three times, which gives the exact size of RAM, a nice smooth number should be output. In my case, on my MacBook Pro, exactly “16”, since it has 16 gigabytes of RAM.
To confirm that os.freemem()
works fine, you can open a few Chrome tabs, run the script, and close them again, and then run the script again. You will see a difference.
4. The URL Module (url)
Since Node.js is often used for the back end of web applications, working with URLs is virtually unavoidable.
The built-in module presented here can make our work easier by providing standard functions for processing URLs.
Split the URL into all important information, such as host, protocol, and port
const url = require("url")url.parse(‘https://medium.com/@louispetrik')
Result:
Url {
protocol: ‘https:’,
slashes: true,
auth: null,
host: ‘medium.com’,
port: null,
hostname: ‘medium.com’,
hash: null,
search: null,
query: null,
pathname: ‘/@louispetrik’,
path: ‘/@louispetrik’,
href: ‘https://medium.com/@louispetrik'
}
Merge base URL and an exact path into one correct URL
url.resolve(‘https://medium.com/', ‘/@louispetrik’)
Result: https://medium.com/@louispetrik
Output the value of the search parameter of the URL
let SearchURL = new URL(‘https://example.org/?product=car')
console.log(SearchURL.searchParams.get(‘product’))
Result: car
Conclusion
That’s it for today, I hope you learned something new and useful. Thanks for reading!