M8 Flashcards
What is Node?
Node is a JS runtime environment and a library.
It uses the same v8 engine as chrome and has an event loop to handle asynchronous code.
Why Node?
It’s JavaScript. A language that is already familiar to many developers, so they can use it across the development stack.
The result of the event-driven asynchronous architecture is that Node.js executes quickly.
What is Nodemon?
Node caches your JS when you start the server, so editing the JS does not update the code that is running on the server.
Nodemon watches for changes to your JS and auto-restarts the server for you.
What is npm?
Node package manager -
npm includes a command line utility for interacting with the npm repository, i.e.
downloading new packages
managing dependencies
What is package.json?
Created by npm
This file holds various metadata relevant to the project.
It is used to give information to npm that allows it to identify the project as well as handle the project’s dependencies such as express.
What is the –save-dev-flag used for?
The –save-dev flag can be used when the package you’re installing is only needed for development purposes, like unit tests or a sass compiler.
Rather than adding the package to the dependencies list in package.json, it gets added to the devDependencies list. The devDependencies list only contains packages needed to develop your package.
What is express?
Express is a back end web application framework for Node.js. It’s like Slim for Node.
Express is lightweight and unopinionated.
What is semantic versioning?
Semantic versioning is a set of rules that define how version numbers should be used. It aims to make things consistent between developers.
Given a version number MAJOR.MINOR.PATCH, increment the:
major
May break the API (change how the package is used).
Devs will have to change their code when they use a new version of the package.
minor
Should not break the API.
No code changes should be required to update the package.
patch
Bug fixes.
What is routing?
Routing connects HTTP verbs and URLs to appropriate code to handle them.
What is dynamic routing?
Dynamic routes make use of placeholders.
With Express, a placeholder is indicated by a colon followed by a placeholder name.
URLs may also include query strings. I.e. key-value pairs following a ?.
req. query: data from GET URL
req. params: data from route placeholder
How do we use Node with MySQL?
Using a package called promise.mysql, which wraps function calls with promises.
What is MongoDB?
What are Documents, Collections and Fields?
Not a relational database.
It is a different way of thinking about database storage: collections and documents.
Document
A JSON object stored in the DB.
Collection
An array of documents - lots of JSON objects.
Field
A key-value pair. Remember JSON consists of key-value pairs.
Difference between MySQL and MongoDB?
The main difference between putting data into MySQL vs MongoDB is that you are not constrained to a certain schema.
The fields don’t have to be the same for each object.
The DB structure is no longer set in stone.
You just store what you need without having to change table definitions.
Advantage: flexible document schemas. MongoDB’s document model allows virtually any kind of data structure to be modelled and manipulated easily.
Mongo DB CRUD operations?
Create - db.collection.insertOne/Many()
Read - db.collection.find();
Update - db.collection.updateOne/Many();
Delete - db.collection.deleteOne/Many()
What are Modules?
A module is a class or group of related functions contained in a file or folder.
Modules help organise and better structure the code of an application.
Modules should be self-contained and reusable.
There are three types of modules in Node:
Core or built-in modules.
Third-party modules.
Custom or local modules.