Ultimate Node.js Handwritten Notes – Master Backend Development!, Lecture notes of Programming Languages

Get backend-ready with this clean and structured handwritten guide to mastering N — the engine behind modern web apps!

Typology: Lecture notes

2023/2024

Available from 09/01/2025

nour-bek
nour-bek 🇩🇿

10 documents

1 / 86

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56

Partial preview of the text

Download Ultimate Node.js Handwritten Notes – Master Backend Development! and more Lecture notes Programming Languages in PDF only on Docsity!

te INDE X t Topic 1 _[Node.js Tutorial on 2. {install Node.js Windows 3 [Nodes First Example 4 Li Node jg Console IG 5 |Nodeje REPL 3 | 6 _|Node. js NeM Lf INadeds CL options [2 % 1Node js Globals 5 9. INode is OS iG lo |Node. |g Timer {2 _INodejs Errors 20 INOde js DNS YW Node is Net QQ 4, Node is Crypto 24 15. INocle.js T15/55L wa Node js Dehugger 299 [1 INode js process 29 18. INode._ {5 Child process yl \9 Node {5 put fers 34 Node. js Streams 37 Node. Js File Streams 39 2 INocde js Path 44 6 str} ngDdecoder UG 2u, Invade. |s Query String 47 5 Node | {6 ZB 43 26. INode, is assertion hg Nodes VB 50 2 Ys 8.1 Node.iS callbacks ~ 52 | 23.[Node jis Events o4 O.|Nodeje Punycode 56 DLE Nocleis TTY 53 = Node.js Web Modules 6\ 3B MySQl Create Connection - 4 mat Ql Create Datahase 64 35 MyS5al Create Table 65 I 36.) MySaL res Recoyd.. 63 | Q date Record 10 | 38 Imy sau Delete Recnrd u My Sa Select Record ped i My 50 ele nro ve iS M AL Drop Fable 15 |. Nodejs Mongo Dp lalCreate Connection 16 Create Database 16 LalCcreate Collection _— i us.| MongoDB Insert L 4T8 4b MongoDB Select 30 !mongaDB Al lery _ 131 | LBL MongndB Sorting __ 18d | 43} Mongodp Remove : 24 ml Smit. Ff | Llo is Asynchronous and Event Driven: Pili | All APIS of Node,js-Hbrary—ore_asynchronous jg ~ Non-blocking. $0 a Nade js based. Server never > gaits for Gh API to return data. The Server moves to the -next_API after Calling it _aind_a_hotifatigs” mechanism_of events of Node 4s to.get a Pesponse from the “previous Ap] my is alan a yYeason: that it is Very foe et aetna Single threaded: bine f Node js follows a Single threaded Model With ~ Event looping. , Highhy Scalable: Node. is is highly Scalable because event mebhanism _ helps the Server to Pespond ina Noh- blocking way. No buffering’ wi ayi -Nodejs cuts down the over r 0 8 ‘O_and Video files Node. js appl-— Cations nevey buffer any d icati simply output the data in chunks. — en Source; Nodejs has an open Source Community Which— has produced mony excellent madules ta add — Additional Capabilities to Node js applications — Node.js {5 released Under the MIT license" The following diagram specifies Some. important Parts of Node jG: Callback ee! f Z Net / Error Handling a Crypto MEE . To install and Setup Gn environment for Node. js, you —__|lneed_ the following two. softwares ANailable Gn _your Camputer: Text Editor —2 Node js Binary instaltahle Mext Editor: ——The text fditor {5 Used to ty e dig Used in Windows, Vim Or vi Can be Used on lalindows as Well as Linux or UNK sae | Mame and version of the text editor can be differ classmate. (O a oie P) Aho ejs-web_oppation-contoins the folowing — _—three_parts (thet crecthe~ sel To load Node jamahi a (Create Server: You have_to establish Server which Will listen to _ ___client's Fequest Similar to Apache HTTP Server L spend potest Qnd_return response: Server Creeited in the second Step will read HTTP Yequest made by client Which can be GQ browser or _ Console and return the response L__ Follow these steps: ' 4. \\mport_ required m —__The first step is to Use ?repainel dvecthe tonal — http module ana store returned HTTP instance into http Variable far example: Var bttp = require ("http"); 2 || [Create Server: [ln the Sernnd step. ‘you hove to Use created http instance tp.createServer() method. to Create Server —instance and then bind it at. -port_30 method associated With server instance. Pass it a -—iflunction With request and Pesponce parameters and rite_the Sample implementation to return "Hello | ae Inlovld": For example: http. create Saenlfanctionlreguest.reseonse)f Herat the HTTP. header _ If ETP Status: 200: ok : - = JJ Content Type: text/plain i t response Write Head (200 Content-type’. text/pbit) //send the response body as "Hello World" a response end’ Hello Waorld\h’ yy Z 3). listen(Bo81); Z /) Console lai) print the message z= Consal¢. log Gepyey running at http: /110710.0.1:308 ul - Combine Step 1 ond step2 together in a File named “main .js” rare Node. js Console module provides a Simple Clebugging console similar to Javascript onsale Mechanism Provided hy web browsers, There are three console methods that are used to_Write Gind tdy, js Stream: 1 Console. log (| 1 ed Console. error!) L ZConsole. Warn() | e Console. loq(l Inction is : | used tod Simple message On Console omnes onsale log (Hello Java T point): Open Node js Command Prompt Hoe ! | Cle: Console example. $8 : a const, hame = John = #fnamef! Dank me — Console. lajaen (Don — With me!) a Open Node.jsComrnand prompt and run the following Code: = hode Console example 4.15 + (ER * — term REPL Stonels for Read Eval Print and — Loop \t specifies a computer environment like QO Window Console or a Unix! Linux Shall _wihere you Can enter the Commands — and the system sespelnns th ane fate in_an_interactive mode ar Environment e Noclejs or node come bundleal with REP erironment. Fach port. of the REPL eovironmett has a Specific Work. classmate (Ome CO Read: It read user's input; parse the input into JavaScript data - ores in memory Eval: of Ib takes and evaluates the data structure Print: \t_prints the result. tt lanes the above command until user press ctrl-¢. twice. ans After starting REPL hodé Command prompt put ony — mathemntical expression. Example: 710 +20 -5 25 5 Variables are used to store Values Qnd print later. lf Vou dort use Var keyword then Value is stored In ’ the Variable and printer Whereas if var _keyiniord is e1, then Value is stored but not printed. You Can orint Variables Using _consale.log \) Example: 20 =s0 50 > Var b=50 undefined >_atb 7 400 O20) pit termintes the Node rep} 4 up/down keys: \tis Used to See Command his tory_and modify Previous commands 5. tab keys: |t Specifies the list _Of Current Command ¢_ help: _\t Specifies the list of all commands Itis Used to exit from multi-line Capressions 3. Y: i It_is Used to exit from multi-line expressions 2 ilename: |t_ Saves Current hode rep! Session to a file me: ‘pep|_ Session i ii. \slhich are searchable O elt also provicles Command li ign management Ona _~ kages, do ver Node js Pac! t_Of Node {s packages. dependency managemen PR The npm comes bundled With Nodes installables in version after that v0.62 You can check the Version by opening Node {s Command prompt ___ nel_typing the fallawing command: Npm Version ~_Tistoliing 2 Npm install module Name> ’ =a Apm Uninstall express aE Search xD pece pia iS A Wide variety of : — lin Noel 2.46 These Options Provide multiple lays — Options - | i. ——} —_| \y ==Version | | 1S Useed | ——-—_] | tO_print Hodes version No — Ings It_silence all pracess Warnings _42 ||--trace- lalarnings lt prints stack fraces for process Warnings. 43 ~ tree Syne- io It prints a stack tyare whenever synchronous i/o. iS detertec after the first turn of the event. loop Mhi--Zero - Fil) — buffers Automatically Zero- Aiis all Nelly allocated buffer and ‘slowhuffer instances r= trark—heap -Obiects ; 3 It tracks heap Object Allocations for heap Shapshots 16 | prof = pracess [C_processes \g profiler aibat gaaiel the v& Option —— prof T= Vg — It prints V8 Command line Options iS --t\9 - chiper list = ligt Its eejtnnes n i : : & 2 ee cdeJstobe built with crypts maa J9 “=~ enable fips classmate, 4 | OREO) It enables fips - Compliant cp ypto at Startup (requires Nede.js to be bull Iaith, /configure —— apenssi-fins) == force — fips 2) It forces fips - compliant Crypto on Startup, (cannot he_ disalhed fram script cade) -~ icU-data-dir=4\, It Specifies CU data load path Nade.js_ global oblects ave Global in nature and available In_all_modules. You dont Reed to include these objects {in Your application; rather they Con be ! These objects are modules fanctions Strings and Object: etc. Some of these obierts arent Actually th the glohal Scope but in the macdule Scope It is a string It Specifies the name Of the “directory that Currently Contains the eo Console .|og(__ dirham e) It specifies the filename of the Code heina exerted This is the pegolved asolute path of this Code Sle. The Nalue jnside cl module is the path to that module file, Filé: dlnhal- example 2.5 Console. lag Filename); TR classmate. This method returns the ehdianness of the cpu. Its posible Nalues are ‘BE’ for big enelian Or ‘Le’ for little endian 103. freeemem|) This method returns the Omount Of free System memory in bytes Os.homedirU This method returns the home directory of the current USer. os hostname) This Method is used to peturns the hostname of the OPperati ny system. 10S] () This Method returns an array containing the 1.5. and ts minute load averages. The load Avevage “is a time farc- tion taken by System Octivity, Calculatect by the Operating System and expressed as a fractional) Humber 103 Netiniork interfaces |) This method returns a list of network interfaces OS. Dlatform() This Method peturns the operating system platform of the Punning Computer ie.'darwin' 'win32' ‘freebsd’, ‘Vipux’, 'sunos! etc OS. release () 1S “Method returns the Operating system release ~tseute 44 Mos tmoelir () = This method returns the operating System's efault clirectory for temporary files I Os. total mem/) This. method returns the total amount of System Memory in bytes 7 13.108 tyoe() This method returns the operating System name. For example 'Jinwr' on linux. ‘darwin’ on 0s x Qnd _"Windogis ht’ On Windowe [blog uptime() This method returns the system Uptime in Seronds. IS: los userinfo (Coptions3) This method returns the suhset of the Password _ file entry for the current effective User. ———}ede.jsTimer F ! }S Timer finctions aye Qlobal functions You. crit need to use reguire() function in onder tp use timer functions alse tlmmediate() It is used to execute set lmmediate 1° | L etMnteryal(): | & tis Used to define a time - interval.