/nodejs-certification

🎓 This repository contains examples that I have done for my own preparation for the Nodej.js certification exam - Application Developer (JSNAD).

Primary LanguageJavaScriptMIT LicenseMIT



My own preparation for Node.js Certification

🎓 This repository contains examples that I have done for my own preparation for the Node.js certification exam - Application Developer (JSNAD).

This content is not official from the OpenJS Foundation or from Node.js.



🔖 Description

I have been working in this repository for several months. I have wanted to share OpenSource examples that I have developed for my own preparation. These examples are organized by folders for each Node.js API.

📖 Temary

Usage & Example
Assertion Testing
Buffer
Child Processes
Cluster
Console
ECMAScript Modules
Errors
Events
File System
HTTP
HTTP/2
HTTPS
Inspector
Internationalization
Modules
Net
OS
Path
Performance Hooks
Process
Query Strings
Readline
REPL
Report
Stream
Timers
Utilities
V8
VM
Worker Threads
Zlib

💪 JSNAD Domains & Competencies

  • Buffer and Streams – 11%
    • Node.js Buffer API’s
    • Incremental Processing
    • Transforming Data
    • Connecting Streams
  • Control flow – 12%
    • Managing asynchronous operations
    • Control flow abstractions
  • Child Processes – 8%
    • Spawning or Executing child processes
    • Child process configuration
  • Diagnostics – 6%
    • Debugging Node.js
    • Basic performance analysis
  • Error Handling – 8%
    • Common patterns
    • Handling errors in various scenarios
  • Node.js CLI – 4%
    • Node executable command line flags
  • Events – 11%
    • The event system
    • Building event emitters
    • Consuming event emitters
  • File System – 8%
    • Input/output
    • Watching
  • JavaScript Prerequisites – 7%
    • Language fundamentals
    • Scoped to core language features introduced since EcmaScript 1 and still heavily used today
  • Module system – 7%
    • CommonJS Module System only
  • Process/Operating System – 6%
    • Controlling the process
    • Getting system data
  • Package.json – 6%
    • Package configuration
    • Dependency management
  • Unit Testing – 6%
    • Using assertions
    • Testing synchronous code
    • Testing asynchronous code

🌍 Websites of Interest

📌 Methodologies and Guidelines

ESTlint, tool for identifying and reporting on patterns found in ECMAScript/JavaScript code.
NPM ESLint
NPM ESLint | Airbnb

✅ Prerequisites

In order to work with this project, your local environment must have at least the following versions:

  • NodeJS Version: 14.xx
  • NPM Version: 6.14.7

📐 How to work with this project

Install Dependencies

$npm i

Running the App

$node ./src/'folder'/'file.js'

Generate the SSL Certificate for localhost

# If you want use http2 you need generate localhost certificate
$openssl req -x509 -newkey rsa:2048 -nodes -sha256 -subj '/CN=localhost' -keyout localhost-privkey.pem -out localhost-cert.pem

📂 Code scaffolding

/
├── assets 🌈                     # Images Sources.
|   └── ...                       # ...
|   |
├── env 🔌                        # Configure enviroments deploy.
|   └── ...                       # ...
|   |
├── src 💯
|   ├── usage-example             # Usage & Example.
|   |   ├── example01             # Http server return pain text.
|   |   └── example02             # Http server return json object.
|   |
|   ├── assertion-testing         # Assertion Testing.  
|   |   ├── example01             # Equal numbers or not with assert.strictEqual method.
|   |   ├── example02             # Equal numbers and string or not with assert.equal method.
|   |   ├── example03             # Equal arrays values and structure or not with strict.deepEqual method.
|   |   ├── example04             # Equal objects values and structure or not with strict.deepEqual method.
|   |   └── example05             # Http request with Reject results and objects results with structure and typeof control.
|   |
|   ├── async-hooks               # Async Hooks.
|   |   ├── example01             # Create http server with external request to get content. This functions launch async hooks and save into .log file.
|   |   ├── test.log              # Log example file.
|   |   └── ...                   # ...
|   |
|   ├── buffer                    # Buffer.
|   |   ├── example01             # Create first safe and not Buffer empty and with string.
|   |   ├── example02             # Get length of string and buffer string.
|   |   ├── example03             # Is Buffer and is Encoding functions.
|   |   ├── example04             # Work with compare, concat, equal, includes, indexOf, lastIndeOf, keys and slice functions.
|   |   ├── example05             # Work with toString and toJSON functions.
|   |   └── ...                   # ...
|   |
|   ├── child-processes           # Child Processes.
|   |   ├── example01             # spawn function.
|   |   ├── example02             # exec and execSync functions.
|   |   ├── example03             # spawn and spawnSync functions.
|   |   ├── example04             # exec and spawn functions with custom sh file.
|   |   ├── example05             # exec and spawn functions with magick tool (you need install imagemagick library).
|   |   ├── example06             # execFile and execFileSync functions.
|   |   ├── example07             # fork function with example messages to childs.
|   |   ├── example07-sub01       # sub process message fork function.
|   |   ├── example07-sub01       # sub process message fork function.
|   |   ├── example08             # fork function with process ls and sh.
|   |   ├── example08-sub01       # sub process spawnSync ls fork function.
|   |   ├── example08-sub01       # sub process spawnSync sh fork function.
|   |   ├── test.sh               # Sh example file.
|   |   ├── cat.jpg               # Image cat example.
|   |   └── ...                   # ...
|   |
|   ├── cluster                   # Cluster.
|   |   ├── example01             # Show CPUs number and create a cluster for each core.
|   |   ├── example02             # Control cluster waiting or working any task.
|   |   └── ...                   # ...
|   |
|   ├── console                   # Console.
|   |   ├── example01             # Basic console log, error and warn.
|   |   ├── example02             # Console log with params added.
|   |   ├── example03             # Show and get log and save into .log files (out and error files).
|   |   ├── example04             # Clear console with setTimeout into async function.
|   |   ├── example05             # Assert, count, countReset.
|   |   ├── example06             # Group and groupEnd.
|   |   ├── example07             # Time and timeEnd.
|   |   ├── example08             # Table with arrays of numbers, objects and more arrays of strings.
|   |   └── ...                   # ...
|   |
|   ├── esm                       # ECMAScript Modules.
|   |   ├── example01             # Import esm module with .js extension file.
|   |   ├── example02             # Import esm module from "libs" folder into your js application with .js extension file.
|   |   ├── example03             # Import esm submodule from "libs" folder into your js application with .js extension file.
|   |   └── ...                   # ...
|   |
|   ├── errors                    # Errors.
|   |   ├── example01             # Variable no defined into try/catch.
|   |   ├── example02             # With properties of an object in try/catch.
|   |   ├── example03             # In callback functions.
|   |   ├── example04             # In try/catch with async and sync functions.
|   |   ├── example05             # Custom message Error into throw.
|   |   └── ...                   # ...
|   |
|   ├── events                    # Events.
|   |   ├── example01             # Differents instances and times.
|   |   ├── example02             # Define arguments and show.
|   |   ├── example03             # Extends class EventEmitter and create main scope with custom properties.
|   |   ├── example04             # What happens to the functions: setTimeout, setImmediate and process.nextTick.
|   |   ├── example05             # Handling events only once.
|   |   ├── example06             # Remove event with removeListener.
|   |   ├── example07             # Set Max Listeners to event with setMaxListeners.
|   |   └── ...                   # ...
|   |
|   ├── file-system               # File System.
|   |   ├── example01             # Open and close file by name with concrete path.
|   |   ├── example02             # Open and close with Url and Buffer.
|   |   ├── example03             # Get File Descriptors with stat function from json and txt files.
|   |   ├── example04             # Open folder and file details with opendirSync and openSync functions.
|   |   ├── example05             # Read folder and file content with readdirSync and readFileSync functions.
|   |   ├── example06             # Get folder content with Callback, Sync and Promises.
|   |   ├── example07             # Get file list of folder and content files with Sync.
|   |   ├── example08             # Get if directory is or not directory and file is or not file.
|   |   ├── example09             # Access function for get if file exist or not.
|   |   ├── example10             # Append function for include new data inside file.
|   |   ├── example11             # Chmod function for set and change permissions of a file.
|   |   ├── example12             # Chown function for set and change owner and group of a file.
|   |   ├── example13             # Copy function for copy file from origin to destination.
|   |   ├── example14             # Create Read Stream from file for get all content and others.
|   |   ├── example15             # Create file and Write Stream of new file for save all content.
|   |   ├── example16             # Create symbolic link with link function.
|   |   ├── example17             # Create directories with mkdir, mkdirSync.
|   |   ├── example18             # Create temp directories with mkdtemp and mkdtempSync.
|   |   ├── example19             # Rename file with rename and renameSync functions.
|   |   ├── example20             # Remove folders with rmdir and rmdirSync functions with recursive option.
|   |   ├── example21             # Remove files with unlink and unlinkSync functions.
|   |   ├── example22             # Create listener for get if change the folder and files content.
|   |   └── ...                   # ...
|   |
|   ├── http                      # HTTP.
|   |   ├── example01             # Get methods and status codes from http.
|   |   ├── example02             # Create http server and show lifecycle-events.
|   |   ├── example03             # Create http server with custom routers and reponses for POST or GET methods.
|   |   ├── example04             # Request to url with method GET and port 80 and received JSON object.
|   |   ├── example05             # Request to url with method POST and port 80 send and received JSON object.
|   |   └── ...                   # ...
|   |
|   ├── http2                     # HTTP2.
|   |   ├── example01             # Create http2 server and response html elements.
|   |   ├── example02             # Create http2 server and show lifecycle-events.
|   |   ├── example03             # Create http and http2 server and see all differences.
|   |   |   ├── example03-http    # Create http server and return static file. See that the connection open and close for each request.
|   |   |   └── example03-https   # Create http2 server and return static file. See that the connection open one time and not close for each request.
|   |   ├── example04             # Create http2 server and with html file and push css and js file.
|   |   └── ...                   # ...
|   |
|   ├── https                     # HTTPS.
|   |   ├── example01             # Create https server and response html elements.
|   |   ├── example02             # Request to url with method GET and port 443 and received JSON object.
|   |   └── ...                   # ...
|   |
|   ├── inspector                 # Inspector.
|   |   ├── example01             # Create inspector instance and config host and port.
|   |   ├── example02             # Send console log, warn, info and error.
|   |   ├── example03             # Send console table.
|   |   ├── example04             # Create new session for any inspector and report via console.
|   |   ├── example05             # Create new session for any inspector and write profile.cpuprofile file.
|   |   └── ...                   # ...
|   |
|   ├── intl                      # Internationalization.
|   |   ├── example01             # toLowerCase and toUpperCase functions with String.
|   |   ├── example02             # Collator functions for get order string and sort string by order.
|   |   ├── example03             # DateTimeFormat for get date with differents languaje and formats.
|   |   ├── example04             # NumberFormat for format numbers with differents languaje and formats.
|   |   └── ...                   # ...
|   |
|   ├── modules                   # Modules.
|   |   ├── example01             # Module Exports and Require consts with strings values.
|   |   ├── example02             # Module Exports and Require function for sum two digits.
|   |   ├── example03             # Module Exports and Require class with methods.
|   |   ├── example04             # Module Exports and Require classes extends with methods.
|   |   ├── example05             # Module Exports and Require classes extends with static method.
|   |   ├── example06             # Export Default and Import class extends with static method.
|   |   ├── example07             # Export and Import classes extends with static method.
|   |   ├── example08             # Two Require of the same Module assign with Require Cache just once.
|   |   ├── example09             # Require JS Module and JSON File.
|   |   ├── example10             # Require JS Module from folder with Package.json file.
|   |   └── ...                   # ...
|   |
|   ├── net                       # Net.
|   |   ├── example01             # Server and Client with emit messages and Close Socket Connection.
|   |   ├── example02             # Server and Client with severals messages from client Without Close Socket.
|   |   ├── example03             # Server and Two Clients send severals messages to all clientes Without Close Socket.
|   |   ├── example04             # Server and two clients and send Message to differents client Pear to Pear.
|   |   └── ...                   # ...
|   |
|   ├── os                        # OS.
|   |   ├── example01             # Get and show CPUs numbers and props.
|   |   ├── example02             # Get and show Free and Total System Memmory.
|   |   ├── example03             # Get and show Home Directory.
|   |   ├── example04             # Get and show Host Name Machine.
|   |   ├── example05             # Get and show Network Interfaces and props.
|   |   ├── example06             # Get and show Platform and Release.
|   |   ├── example07             # Get and show Temporal Directory.
|   |   ├── example08             # Get and show User Info.
|   |   ├── example09             # Get and show Operating System Constants.
|   |   └── ...                   # ...
|   |
|   ├── path                      # Path.
|   |   ├── example01             # Get Basename of current or specific folder.
|   |   ├── example02             # Use basename for get all internal files from folder and get basename of files.
|   |   ├── example03             # Use dirname for get the main folder and all internal files.
|   |   ├── example04             # Use extname for get extension of file name or all path.
|   |   ├── example05             # Get if any path is absolute.
|   |   ├── example06             # Use joins method for concat all string for create a correct path.
|   |   ├── example07             # Use normalize method for create corrects paths.
|   |   ├── example08             # Use parse method for get object with all properties of paths.
|   |   ├── example09             # Use relative method for compare two path and get an absolute path.
|   |   ├── example10             # Use sep method for generate array with split and resolve a structure with folders and files.
|   |   └── ...                   # ...
|   |
|   ├── perf-hooks                # Performance Hooks.
|   |   ├── example01             # Timer and measure for JSON parse and stringify functions examples.
|   |   ├── example02             # Timer and measure for Get all files from specific folders in a function with callback.
|   |   ├── example03             # Timer and timerify wrapper for Get all files from specific folder with function with callback.
|   |   ├── example04             # Timers with severals externals request https for others REST APIs.
|   |   ├── example05             # Show Measure and Mark timers with two Observers
|   |   ├── example06             # Get duration timer of severals require functions of modules.
|   |   └── ...                   # ...
|   |
|   ├── process                   # Process.
|   |   ├── example01             # Use beforeExit event for get when event loop has no additional work to schedule.
|   |   ├── example02             # Send message between procces, one http server and other write into file.
|   |   ├── example03             # Use multipleResolves event for tracking potential errors in an application while using the Promise constructor.
|   |   ├── example04             # Use multipleResolves event with Promise.race() method returns a promise that fulfills or rejects as soon as one of the promises.
|   |   ├── example05             # Use unhandledRejection event for get all promise without catch.
|   |   ├── example06             # Use uncaughtException event for get all error of function without try/catch control.
|   |   ├── example07             # Use warning event for example to get exceeded listener of Event Emitter.
|   |   ├── example08             # The argv property contain all arguments include via CLI.
|   |   ├── example09             # The process.cwd() method returns the current working directory of the Node.js process.
|   |   ├── example10             # The process.emitWarning() method can be used to emit custom or application specific process warnings.
|   |   ├── example11             # The process.execArgv property returns the set of Node.js-specific command-line options passed when the Node.js process was launched.
|   |   ├── example12             # The process.exit() method instructs Node.js to terminate the process synchronously with an exit status of code.
|   |   ├── example13             # Use getegid, geteuid, getgid, getgroups and getuid functions for show info process identity.
|   |   ├── example14             # The bigint version of the process.hrtime() method returning the current high-resolution real time in nanoseconds.
|   |   ├── example15             # The process.memoryUsage() method returns an object describing the memory usage of the Node.js process measured in bytes.
|   |   ├── example16             # process.nextTick() adds callback to the "next tick queue".
|   |   ├── example17             # pid, platform, ppid, release props for get additional data of process and NodeJS release.
|   |   ├── example18             # Returns object the resource usage for the current process.
|   |   └── ...                   # ...
|   |
|   ├── querystring               # Query String.
|   |   ├── example01             # Use querystring.encode for encode json object to url params.
|   |   ├── example02             # Use querystring.decode for decode url with several params to json object.
|   |   └── ...                   # ...
|   |
|   ├── readline                  # Readline.
|   |   ├── example01             # Use createInterface and create question and show user answer.
|   |   ├── example02             # To exit this process you just have to press <ctrl> + C.
|   |   ├── example03             # Get content for show from txt file for create interface.
|   |   ├── example04             # Use "process.stdin" events to get more interactions.
|   |   ├── example05             # Use line, close, pause and resume of readline for get events.
|   |   ├── example06             # Use keypress, keyup and keydown for get "process.stdin" events.
|   |   └── ...                   # ...
|   |
|   ├── repl                      # REPL.
|   |   ├── example01             # Create REPL and press .help for show all help commands.
|   |   ├── example02             # Create and press 2 times ^C again or ^D or type .exit.
|   |   ├── example03             # Run REPL, create a function and execute it..
|   |   ├── example04             # Create "replServer" and use defineCommand for include Specific Commands.
|   |   └── ...                   # ...
|   |
|   ├── report                    # Diagnostic Report.
|   |   ├── example01             # Write error and report to generic json file with an example.
|   |   ├── example02             # Write error and report to concrete file with an example.
|   |   ├── example03             # Launch an error and getReport to show javascriptStack object..
|   |   ├── example04             # Show errors and reports via EventEmitter.
|   |   └── ...                   # ...
|   |
|   ├── stream                    # Stream.
|   |   ├── example01             # Write severals string into file.txt with .write function.
|   |   ├── example02             # Include callbacks for open, ready, finish, open and error events.
|   |   ├── example03             # Write big file with .write method with this result: 1,1G stream-big-example03.txt.
|   |   ├── example04             # Show how many seconds the function fs.writeFile and fs.createWriteStream needs to perform the same task.
|   |   ├── example05             # Create origin and destination Stream and use gzip for compress file destination.
|   |   ├── example06             # Create origin Stream, Custom transform Stream and destination Stream for replace text from origin to destination file.
|   |   ├── example07             # Http server and Read Stream for create gz file from txt file and download with browser.
|   |   ├── example08             # Http server and Read Stream for return html file with gzip encoding.
|   |   ├── example09             # Readable with iterate function with yield.
|   |   ├── example10             # Readable with iterate array.
|   |   ├── example11             # Readable Stream with iterate map with severals objects items.
|   |   ├── example12             # Readable Object with iterate map and two pipes for work with severals Streams Writables.
|   |   ├── example13             # Parallel Pipes with Readable from array with iterate map, transform and Write with two Stream file.
|   |   ├── example14             # Sequentials Pipes with end option to false and Readable and Duplex with write functions more info with timeouts.
|   |   ├── example15             # Sequentials Pipes and Readable with autoClose option to false and Duplex with end option to false and set severals writes functions.
|   |   ├── example16             # Work with Readline and Write Stream to save line by line.
|   |   ├── example17             # Create Stream from origin file, replace all emails to * characters and save into new Stream file.
|   |   └── ...                   # ...
|   |
|   ├── timers                    # Timers.
|   |   ├── example01             # timeout vs immediate.
|   |   ├── example02             # timeout vs immediate with inside timers.
|   |   ├── example03             # timeout vs severals immediate.
|   |   ├── example04             # timeout vs immediate vs nextTick.
|   |   ├── example05             # nextTick with try/catch and not block timeout and immediate.
|   |   ├── example06             # timeout, immediate, nextTick and promises inside this with try/catch/finally.
|   |   ├── example07             # timeout, immediate, nextTick and promises inside this with then/catch/finally.
|   |   └── ...                   # ...
|   |
|   ├── util                      # Util.
|   |   ├── example01             # Use .callbackify method with async function.
|   |   ├── example02             # Use .callbackify method with Promise.
|   |   ├── example03             # Return with .debuglog method param.
|   |   ├── example04             # Return with .debuglog method severals params.
|   |   ├── example05             # Return console with color in terminal and params.
|   |   └── ...                   # ...
|   |
|   ├── worker-threads            # Worker Threads.
|   |   ├── example01             # Create Worker with the same file..
|   |   ├── example02             # Create Worker with differents files for create two parallels tasks.
|   |   ├── example03             # Create two Worker and send messages with parent.
|   |   ├── example04             # Create ten Worker and send messages to parent with finish setTimeout with random time.
|   |   ├── example05             # Create Worker when update the content of local json file for change it and save into other file.
|   |   └── ...                   # ...
|   |
|   ├── zlib                      # Zlib.
|   |   ├── example01             # Compress to zip destination file from txt file how source.
|   |   ├── example02             # Compress jpg file to zip file and decompress zip for get jpg origin file.
|   |   ├── example03             # Create .gz file from jpg file and uncompress with createGunzip method.
|   |   ├── example04             # Create severals .gz file with gzip, deflate and brotli methods. You can see which one is more efficient.
|   |   ├── example05             # Create http server and return html file with Brotli Compress via response Stream.
|   |   ├── example06             # Create http server and Static files into a public folder.
|   |   └── ...                   # ...
|   |
|   └── ...
└── ...

⛽️ Review and Update Dependences

For review and update all npm dependences of this project you need install in global npm package "npm-check-updates" npm module.

# Install and Run
$npm i -g npm-check-updates
$ncu

Happy Code

Created with JavaScript, lot of ❤️ and a few ☕️

This README.md file has been written keeping in mind