• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/41

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

41 Cards in this Set

  • Front
  • Back

Who is the creator of Node.js and when was it initially released?

Ryan Dahl is the creator of Node.js. The development was sponsored by Joyent and it was initially released in 2009.

What is npm?

npm is Node.js' package ecosystem. It is the largest ecosystem of open-source libraries in the world. It is also the name of the command line package manager used to interact with npm.

What is the name of the file which npm uses to identify the project and its dependencies?

Its name is package.json.


What are the names of at least three of the most popular Node.js frameworks?

Express, Sails, Loopback, Koa, Hapi, Meteor, etc.

What is the name of at least one framework that utilizes Node.js for development of desktop apps?

Electron

What is the alternative to the Node package manager (npm), which was introduced by Facebook in 2016?

yarn

What is the difference between dependencies and devDependencies?

Both are defined in the package.json. dependencies lists the packages that the project is dependent on. devDependencies lists the dependencies which are only required during testing and development.

What is REPL and how can you access it from the command line?

REPL stands for "Read Eval Print Loop." It is an interface for easily running Node.js code. It can be started from the command line using the node command.

What is the name of the JavaScript engine that Node.js is built upon?

Chrome's V8 engine.


Does Node.js operate in a single-threaded or multi-threaded fashion?

Node.js operates on a single thread.

What is the event loop?

Node.js processes incoming requests in the event loop. It is what allows Node.js to perform non-blocking operations despite the fact that JavaScript is single-threaded.

What is Node.js' Cluster module?

A module used to take advantage of multi-core systems, so that apps can handle more load.

What is Node.js' Cluster module?

A module used to take advantage of multi-core systems, so that apps can handle more load.

Which keywords are used to export and import an object or a function from a module file?

module.exports is used to export an object or a function. require is used to import one.

Which keywords are used to export and import an object or a function from a module file?

module.exports is used to export an object or a function. require is used to import one.

Which global variable can be used to access information about the app and the environment that it runs in?

The process variable

What is __dirname?

A global variable which returns the absolute path of the directory containing the currently executing file.

What is a blocking function?

Unlike non-blocking functions, a blocking function's execution must be completed before other statements are executed.

Which is the first argument usually passed to a Node.js callback handler?

It is an error object, which is null or undefined if an error did not occur.

What does "callback hell" mean?

Plenty of nested callbacks lead to callback hell. They make code difficult to read and maintain. One of the ways to deal with callback hell is to use the async/await syntax.

What are async and await?

A function marked with the async keyword can contain an await expression. The await expression pauses the execution of the function and waits for the resolution of the passed Promise. It then resumes the function's execution and returns the resolved value.

What are async and await?

A function marked with the async keyword can contain an await expression. The await expression pauses the execution of the function and waits for the resolution of the passed Promise. It then resumes the function's execution and returns the resolved value.

What is the difference between setTimeout and setImmediate?

setTimeout is used to run a function after a certain minimal timeout. setImmediate is used to run a function once the current event loop completes.

What is the difference between setTimeout and setImmediate?

setTimeout is used to run a function after a certain minimal timeout. setImmediate is used to run a function once the current event loop completes.

Does the fs module, used for file-based operations, offer the possibility for synchronous or asynchronous reading and writing?

fs offers both synchronous and asynchronous methods for reading from and writing to files.

What are the two methods in the fs module that can be used for reading a whole file at once?

fs.readFile and fs.readFileSync.

What are the two methods in the fs module that can be used for reading a whole file at once?

fs.readFile and fs.readFileSync.

What keyword do you need to use to insert a debug breakpoint?

The debugger keyword.

What is an error-first callback?

Error-first callbacks are used to pass errors and data. The first argument is always an error object that the programmer has to check if something went wrong. Additional arguments are used to pass data.



fs.readFile(filePath, function(err, data) {


if (err) {


//handle the error


}


// use the data object


});

How can you avoid callback hells?

To do so you have more options:



modularization: break callbacks into independent functions


use Promises


use yield with Generators and/or Promises

How can you listen on port 80 with Node?

You should not try to listen with Node on port 80 (in Unix-like systems) – to do so you would need superuser rights, but it is not a good idea to run your application with it.



Still, if you want to have your Node.js application listen on port 80, here is what you can do. Run the application on any port above 1024, then put a reverse proxy like nginx in front of it.

What’s the event loop?

Node.js runs using a single thread, at least from a Node.js developer’s point of view. Under the hood Node.js uses many threads through libuv.


Every I/O requires a callback – once they are done they are pushed onto the event loop for execution.

What tools can be used to assure consistent style?

JSLint by Douglas Crockford


JSHint


ESLint


JSCS

What’s the difference between operational and programmer errors?

Operation errors are not bugs, but problems with the system, like request timeout or hardware failure.


On the other hand programmer errors are actual bugs.

What are the key features of Node.js?

Asynchronous event-driven


Fast in Code execution


Single Threaded but Highly Scalable


Node.js library uses JavaScript

Explain how do we decide, when to use Node.js and when not to use it.

It’s ideal to use Node.js for developing streaming or event-based real-time applications that require less CPU usage such as:


Chat applications.


Game servers.


Good for collaborative environment.


Advertisement servers.


Streaming servers.



When to not use Node.js?


However, we can use Node.js for a variety of applications. But it is a single-threaded framework, so we should not use it for cases where the application requires a long processing time. If the server is doing some calculations, it won’t be able to process any other requests. Hence, Node.js is best when processing needs less dedicated CPU time.

How to get Post Data in Node.js?

Following is the code snippet to fetch Post Data using Node.js.



app.use(express.bodyParser());


app.post('/', function(request, response){


console.log(request.body.user);


});

How to make a Post request in Node.js?

The following code snippet can be used to make a Post Request in Node.js.



var request = require('request');


request.post(


'http://www.example.com/action',


{ form: { key: 'value' } },


function (error, response, body) {


if (!error && response.statusCode == 200) {


console.log(body)


}


}


);

What is Callback in Node.js?

We may call “callback” as an asynchronous equivalent for a function. Node.js makes heavy use of callbacks and triggers it at the completion of a given task. All the APIs of Node.js are written in such a way that they support callbacks.



For example, suppose we have a function to read a file, as soon as it starts reading the file, Node.js return the control immediately to the execution environment so that the next instruction can be executed. Once the file read operation is complete, it will call the callback function and pass the contents of the file as its arguments. Hence, there is no blocking or wait, due to File I/O. This functionality makes Node.js as highly scalable, using it processes a high number of requests without waiting for any function to return the expected result.

How to avoid callback hell in Node.js?

Node.js internally uses a single-threaded event loop to process queued events. But this approach may lead to blocking the entire process if there is a task running longer than expected.


Node.js addresses this problem by incorporating callbacks also known as higher-order functions. So whenever a long-running process finishes its execution, it triggers the callback associated. With this approach, it can allow the code execution to continue past the long-running task.


However, the above solution looks extremely promising. But sometimes, it could lead to complex and unreadable code. The more the no. of callbacks, the longer the chain of returning callbacks would be. Solution:


1. Make your program modular.


2. Use an async mechanism.


3. Use the promises mechanism.


4. Use generators.

What is the difference between Nodejs, AJAX, and jQuery

The one common trait between Node.js, AJAX, and jQuery is that all of them are the advanced implementation of JavaScript. However, they serve completely different purposes.



Node.js –


It is a server-side platform for developing client-server applications. For example, if we’re to build an online employee management system, then we won’t do it using client-side JS. But Node.js can certainly do it as it runs on a server similar to Apache, and Django not in a browser.



AJAX (aka Asynchronous Javascript and XML) –


It is a client-side scripting technique, primarily designed for rendering the contents of a page without refreshing it. There are a no. of large companies utilizing AJAX such as Facebook and Stack Overflow to display dynamic content.


jQuery –


It is a famous JavaScript module that complements AJAX, DOM traversal, looping, and so on. This library provides many useful functions to help in JavaScript development. However, it’s not mandatory to use it but as it also manages cross-browser compatibility, so can help you produce highly maintainable web applications.