-
Notifications
You must be signed in to change notification settings - Fork 0
Node JS Extra
Sandesh Kota edited this page Feb 6, 2021
·
8 revisions
-
When you create a file in Node.Js, node actually wraps the content and puts it inside a function
- example, if you create the below file
// index.js console.log('Hello'); - node wraps it as below
// index.js function(exports, module, require, __filename, __dirname) { console.log('Hello'); return module.exports; } - And hence you can use these params in your function and the module.exports gets returned. also the same reason why any variable that is created in this file is not global. since it in inside a function.
- example, if you create the below file
-
To create a global values, you can add it to global object (but you shouldn't, that's the whole intention )
global.name = 'Kota';- Example: the process, buffer, setTimeInterval, clearInterval, etc... are all part of this global object and that's why you can use it directly. In actual it is
processis same asglobal.process. You can know this by printing the globalconsole.dir(global, { depth:0 })
- Example: the process, buffer, setTimeInterval, clearInterval, etc... are all part of this global object and that's why you can use it directly. In actual it is
-
Debugging node: using chrome developer tools
- In VS Code:
> node --inspect index.jsand press ctrl+shift+p and select "Debug: Attach to node process" and then select your project -
> node --inspect-brk index.jsthen openchrome://inspectin chrome or there are other tools also
- In VS Code:
-
Node Basics
- Event Emitters (
.emit(), .on()) - Timers (setTimeOut, setTimeInterval, clearTimeImmediate, etc....)
- Buffer
- Stream ( readable, writable, Transform & Duplex)
- fs (File Service)
- promises & async/await
- process
- os
- Event Emitters (