Node.JS Flashcards
CodeWithMosh
Node is a framework?
TRUE / FALSE
FALSE
Node is a run time environment for executing JS code
Node works Synchronise or Asynchronise
Asynchronise
Node is good for?
- CPU intensive sites
- I/O disk network access apps
I/O disk network access apps
how to run a JS file in node?
node “name of file”
how to start node in terminal?
node
how to end node in terminal?
control+c twice
in node there is no window object
TRUE / FLASE
TRUE
window.console.log();
Write the above for Node
global.console.log
there is no window object in NODE instead we use the keyword _______
global
var message = ' '; console.log(global.message); //returns in NODE?
undefined
every file in node is considered a _____
module
to load a module we use the ______ keyword
require
require(‘./logger’);
convert to new ES6 syntax
import ‘./logger’;
what we used to indicated current folder
./
period slash
when using node as best practice what should be changed?
var logger = require(‘./logger’);
console. log(logger);
logger. log(“hello”);
var to const
loading module when importing use const so it does not change
variables and functions are scoped to the ______
modules
what is not valid and why?
exports.log = log;
module.exports.log = log;
exports = log;
//this exports is a reference to module.exports function
exports = log;
The path module provides utilities for working with file and directory paths. It can be accessed using:
const path = _________(‘path’);
require
The ________ module provides utilities for working with file and directory paths.
path
The _________ module provides a number of operating system-related utility methods.
OS
The os module provides a number of operating system-related utility methods. It can be accessed using:
const os = ________
const os = require(‘os’);
The ______ module provides an API for interacting with the file system in a manner closely modeled around standard POSIX functions
fs
filesystem
const fs = ________
const fs = require(‘fs’);
when using File System Module there are Asynchronous and Synchronous methods, what should we generally use?
Asynchronous or non blocking
Asynchronous is associated with blocking or non-blocking
non-blocking
Synchronous is associated with blocking or non-blocking
blocking
const fs = require(‘fs’);
const files = fs.readdirSync(____)
./
dot slash
all async methods take a_____ as the last element
function
a name for a signal that something has happened
event
The events module name is always capilatized because its a __________
class
events module are?
- functions - class - variables
class
emit means
make a noise or produce a signal
const EventEmitter = require('events'); const emitter = new EventEmitter(); emitter.emit('messageLogged');
the code above won’t do anything because it’s missing a _____
listener
const EventEmitter = require('events'); const emitter = new EventEmitter();
emitter.addListener is the same as emitter._____
emmiter.on
const EventEmitter = require('events'); const emitter = new EventEmitter();
emitter.________ is the same as emitter.on
addListener
the emitter.on(); takes two parameters
eventName | The name of the event.
listener The callback function
When creating multiple messages in the code below its best to encapsulate them in a ______
emitter.emit(‘messageLogged’);
object