Section 1

Preview this deck

How do your create, load and install modules?

Front

Star 0%
Star 0%
Star 0%
Star 0%
Star 0%

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Active users

0

All-time users

0

Favorites

0

Last updated

6 years ago

Date created

Mar 1, 2020

Cards (17)

Section 1

(17 cards)

How do your create, load and install modules?

Front

First, you want to make sure your package-JSON file is created. Your "main" is the file that will be loaded when your module is required. In that file, add a function as a property of the exports object (so, exports.propertyName = function() { followed by that function} ). This will make the function available to other code. Then, publish your package to npm using npm publish. On the command line, make a new directory to test that directory outside your project directory, cd into that directory, and install your module by typing npm install <your-module-name>. Then you can create a file, require your module, and run it to see if it works.

Back

What are buffers and streams in Node.JS?

Front

Buffers and streams are what allows data to constantly be returned to the client from the server without transferring large amounts of data at once. Streams are objects that let your read data from a source or write data to the destination in a continuous fashion. Buffers are classes which provides instances to store raw data in chunks and gets passed to a stream object.

Back

What is the structure for requiring a module within your solution?

Front

1.) Node starts looking in the same directory as the program file. Is the module a core module? If YES, return module. 2.) If NO, is the module in the nodes_module folder of the same directory? If YES, return module. 3.) If NO, attempt to move to the parent directory. 4.) Does the parent directory exist? If YES, is the module in the nodes_module folder of that directory? If YES, return module. 5.) If NO, does the module exist inside a directory specified by the node_path environment variable? If YES, return module. 6.) If NO, throw error.

Back

What happens after npm init?

Front

Your package.JSON file is created which gives you all the metadata about your project and will store any dependencies needed.

Back

How does Node.JS utilize the event loop?

Front

Your code runs single-threaded through an event loop that takes in multiple I/0 requests from multiple users. When a request is made or an event is triggered, the loop creates a callback function that delegates that I/O request to Libuv—a multi-platform library that handles these asynchronous functions. The async threads within Libuv are non-blocking, so they're able to process that command to the database without interrupting any other process. Then that result is returned after an x amount of time back to that single threaded loop to be returned to the user. This single-threaded loop overall takes up a lot of CPU, but allows for better real-time, multi-user applications.

Back

What are some ES6 features supported by node?

Front

Spread operator, default function parameters, rest parameters, for of loops, template strings, and more

Back

What are the core modules in Node.JS?

Front

Fs (filesystem), path, http, url, querystring, util, networking

Back

What are some advantages of Node.JS?

Front

1.) Because all of the APIs of NodeJS are asynchronous, Node can execute I/O operations in the background while continuing to process other requests. 2.) Chrome's V8 engine allows our JavaScript code to compile down to machine code at a really fast rate. We can also run JavaScript outside of our browser. 3.) Developers can write both the front-end of the application and the back-end using JavaScript, making it much easier to develop since almost all browsers support JavaScript. 4.) It's open sourced, so it has a large, active community of developers constantly contributing towards its development and improvement. 5.) It allows you to utilize JSON to exchange data between the web server and the client

Back

What are some of the properties within the package.JSON file?

Front

Name, version, description, main, scripts, keywords, test, author, license

Back

What is Node.JS?

Front

Node.js is a server-side JavaScript, cross-platform runtime environment that utilitzes an asynchronous, non-blocking I/O model to help build network applications.

Back

What is npm and what is it's purpose?

Front

Npm stands for "node package manager" and is both a command line tool and an online registry. The command line tool allows you to to install and uninstall packages apart of this online registry created by developers to help you do the things you need to do with your code. You can keep all of your packages up to date, and manage all of your dependencies—packages needed for another package to work properly.

Back

What is EventEmitter and what does it do?

Front

A class that contains all the properties and methods needed to access an event. This class has two methods: on() and emit(). On method takes an event name and a callback function. Once you emit that event, the emit method invokes that callback function.

Back

What is package.JSON?

Front

Package.JSON is the identifier of your project. It is where you'll find the metadata specific to that app such as project name, author, and any dependencies needed for the code to run. Having these dependencies allows your project to install the versions of the modules it depends on. So for example, if you install a module like Express, and require particular dependencies from that module, you can delete the nodes_module folder and still have access to those dependencies you already injected. This file is structured in JSON format which allows it to be easily parsed by machines.

Back

What is package-lock.JSON?

Front

The file of your project that records the exact version of each installed package which allows you to reinstall them. If you update the version of a particular package, that change will not reflect in the package.JSON file, but instead in your package-lock.JSON.

Back

What is the Event Module?

Front

A built in module where you can create, fire, and listen for your own events. You must use the require method to include this modules. All event properties are an instance of the EventEmitter object. To access these properties, create an EventEmitter object.

Back

What is Express?

Front

Back

How do you create a Node.JS application?

Front

1.) Create your parent folder 2.) Open your CLI (command prompt) and cd into that parent folder 3.) Make a directory for your Node app by using the "mkdir" command plus the name of your directory 4.) Cd into that directory 5.) Initialize your node app by using the "npm init" tool to set up a new npm package—this is how you'll get your package.JSON file. 6.) Agree to all the prompts. 7.) Now you can go into your text editor and create your app!

Back