Node JS Flashcards

1
Q

What is Node JS?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

node.js cheetsheet

A

https://www.codecademy.com/learn/learn-node-js/modules/intro-to-node-js/cheatsheet

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

npm init

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

npm

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

npm install

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

npm start

A

starts the application.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How to quit the application?

A

On the active session, hold Ctrl+c.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

setImmediate(functionToExecute)

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

fs

A

A module responsible for all the async or sync file I/O operations.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

fs.readFile()

A

A method used to read files on your computer.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

require(“module_name”)

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

REPL

A

Read, Evaluate, Print, and Loop. To use REPL, type “node” and press [enter]. This is a quick way to test simple JavaScript code.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

core modules

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

custom modules

A

custom modules are imported using require(“./xxxx”) and a specified file path.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

process module

A

a global module that gives access to information about the Node.js runtime environment.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

console module

A

exports a global console object allowing the terminal to act as a debugging console.

17
Q

path module

A

a global module that provides utilities for working with file and directory paths.

18
Q

util module

A

contains methods used to maintain and debug your code.

util.promisify() - takes an input for the function and returns them as a promise.

19
Q

os module

A

provides methods to retrieve information about the computer, OS, and network interfaces.

20
Q

fs module

A

a global module allowing you to work with your file system.

21
Q

http module

A

a global module that creates an HTTP server that listens to server ports and gives a response back to the client.

22
Q

package

A

a third-party module wrapped up with the list of that module’s own dependencies.

23
Q

package.json

A

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.
24
Q

express js

A

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.

25
Q

node modules with require, exports, and imports

A

https://adrianmejia.com/getting-started-with-node-js-modules-require-exports-imports-npm-and-beyond/

module.export starts off as an empty object.

26
Q

revealing module pattern

A

A design pattern where we only want to expose the properties and methods needed via a returned object.

example:
var data = “123”

function showData() {
return data;
}
// here only the function is accessible.
module.exports = showData;

27
Q

when code is ran through Node…

A

The code is wrapped in an IIFE, giving us access to the module object, require, etc. :
(function (exports, require, module, __filename, __dirname) {
// our code here
var greet = function() {
console.log(“Hello”);
}
module.exports = greet;
}

28
Q

module.exports vs exports

A

https://stackoverflow.com/questions/16383795/difference-between-module-exports-and-exports-in-the-commonjs-module-system

29
Q

event emitter

A

an object that can emit named events, which can be listened to by registered listeners. When an event is emitted, all listeners are invoked.

example:
const EventEmitter = require(“events”);
EventEmitter.on(“listen”, () => {
console.log(“hello”)
})
EventEmitter.emit(“listen”);

30
Q

module, package, dependency

A

Pretty much interchangeable terms to describe re-usable code.

31
Q

nodemon (3rd party module)

A

a tool that helps develop Node.js based applications by automatically restarting the node application when a file change in the directory is detected.

32
Q

how to uninstall a node module

A

“npm uninstall PACKAGE_NAME”.

To uninstall all modules, delete the node_modules directory and delete the package-lock.json file.

33
Q

streams

A

objects that let you read data from a source or write data to a destination in a continuous fashion.