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.