Node.js Fundamentals Crash Course Notes
2 min readApr 30, 2020
I was recently learning Node.js and while learning the fundamentals I created some notes for my personal reference but I thought they could be of use to others as well.
Below are the things I learned from this video by Mosh Hamedani.
- Node.js is a runtime environment for running JS code
- Has an Asynchronous and non-blocking architecture
- Follows a single thread model
- Uses EventQueue
- Ideal for I/O intensive apps
- Not ideal for CPU intensive apps
- Node.js is basically a C++ program
- Runs on Chrome V8 Engine
- Uses modules such as os, fs, events, HTTP
- Some functions are globally available: setTimeout(),clearTimeout(),setInterval(),clearInterval()
- Global is the central object
- Global is similar to the Window object that browsers provide to normal JavaScript
- Thus in Node.js
console.log=global.console.log;
- Whereas in browsers
console.log=window.console.log;
- Unlike in Window, every variable is not added to “Global”
- Every file in Node.js is a Module
- Variables and Functions are scoped to that file/module only
- To export anything from one file/module use the exports object
module.exports.logger=log//Logger is the external name whereas Log is the internal name of a method
//they both can be same as well
- To use a different module in any module, ‘require’ is used
require('./logger/);
//require returns a 'export' object from the 'logger.js' file/module
- JS Hint can be used to do pre-compile error scanning of Node.js files
- For single exports, one can simply use module.exports
function log(message){
...
}
module.export = log;
- Node.js internally wraps each module inside of a function and runs that as a JS code, this is called Module Wrapper Function
- Node.js has a lot of built-modules such as “path” to deal with files
- EventEmitter module can be used to do event handling
Do share this article and live a few claps if this article helped you in any way :)