Concepts in Focus
1. MERN Stack
MERN stands for MongoDB, Express JS, React JS and Node JS.
It is a JavaScript Stack that is used for easier & faster deployment of full-stack web applications.
2. Node JS
Node JS is a JavaScript environment that executes JavaScript code outside a web browser.
Why Node JS?
- Cross-Platform (Windows, Linux, Mac OS X, etc.)
- Huge number of third-party packages
- Open Source
- Massive Community
3. Running JavaScript Using Node JS
We can run JavaScript using Node JS in 2 ways.
- Node REPL (Similar to browser console)
- Node CLI
3.1 Node REPL (Read-Eval-Print-Loop)
Type
Type
3.2 Node CLI
We can write JavaScript to a file and can run using Node CLI.
4. Module
In Node JS, each JavaScript file is treated as a separate module. These are known as the Common JS/Node JS Modules.
To access one module from another module, we have Module Exports.
- Common JS Module Exports
- Default Exports
- Named Exports
- Modern JS Module Exports
- Default Exports
- Named Exports
4.1 Common JS Module Exports
4.1.1 Default Exports
Exporting Module
The
Importing Module
To import a module which is the local file, use the require() function with the relative path of the module (file name).
Output
4.1.2 Named Exports
We can have multiple named exports per module.
Exporting Module
Importing Module
Output
4.2 Modern JS Module Exports
Modern JS Modules are known as ES6 Modules.
The export and import keywords are introduced for exporting and importing one or more members in a module.
4.2.1 Default Exports
Exporting Module
Importing Module
Output
4.2.2 Named Exports
Exporting Module
Importing Module
Output
- We need to specify .mjsextension while importing ES6 Modules.
- We may or may not need to specify .jswhile importing Common JS Modules.