Node JS Flashcards
What is Node JS?
A cross-platform JavaScript runtime environment to build fast and scalable server-side applications. It embeds and adds additional functionality over Google Chrome’s V8 JavaScript engine. Node uses one main thread. It also uses events to sync states.
node.js cheetsheet
https://www.codecademy.com/learn/learn-node-js/modules/intro-to-node-js/cheatsheet
npm init
A command to create a Node.js project. This creates the package.json and gives you step-by-step prompts.
Use “npm init -y” to keep everything default.
npm
Allows you to download remote packages and manage them via terminal. It is a library and registry for JS software packages. It is the most popular package manager. It allows you to re-use your code in other projects, use other developer’s code, and share your solutions to other developers.
npm install
used to install dependencies from the package.json file.
-use “npm i PACKAGE_NAME” to install the dependency only on the current project.
-use “npm install -g PACKAGE_NAME” to install the dependency globally to be used in any project.
-use “npm i PACKAGE_NAME” with “-D” or “–save-dev” flag to install a package as a dev dependency.
npm start
starts the application.
How to quit the application?
On the active session, hold Ctrl+c.
setImmediate(functionToExecute)
A function used to execute a function right after the current event loop finishes. Essentially the functionToExecute is called after all the statements in the script are executed.
fs
A module responsible for all the async or sync file I/O operations.
fs.readFile()
A method used to read files on your computer.
require(“module_name”)
A function used to load and cache JavaScript modules. You can use destructuring if you only want to access specific objects or functions from an imported module.
The require function returns module.exports.
REPL
Read, Evaluate, Print, and Loop. To use REPL, type “node” and press [enter]. This is a quick way to test simple JavaScript code.
core modules
Core modules are built into Node.js environment. Some of the core modules are in the global scope so you do not need to require() them. Other core modules will need the require() function.
custom modules
custom modules are imported using require(“./xxxx”) and a specified file path.
process module
a global module that gives access to information about the Node.js runtime environment.
console module
exports a global console object allowing the terminal to act as a debugging console.
path module
a global module that provides utilities for working with file and directory paths.
util module
contains methods used to maintain and debug your code.
util.promisify() - takes an input for the function and returns them as a promise.
os module
provides methods to retrieve information about the computer, OS, and network interfaces.
fs module
a global module allowing you to work with your file system.
http module
a global module that creates an HTTP server that listens to server ports and gives a response back to the client.
package
a third-party module wrapped up with the list of that module’s own dependencies.
package.json
A manifest file containing metadata about a project and it’s dependencies.
- The “dependencies” list all the project’s dependencies alongside their version numbers. “devDependencies” indicates that packages are being used specifically for development.
- Anyone who wants to work with you on your project can download your package.json file and run “npm i”. This will install the listed dependencies they can use.
express js
a web application framework for Node.js that helps simplify the process of building web applications. It provides a set of tools and features for creating APIs, web servers, and web applications.