Node.js
ELI5: Node.js
Node.js, by itself, is just a JavaScript runtime environment. It allows you to run JavaScript code outside of something like a web browser. Node.js provides an event-driven architecture and a non-blocking I/O API designed to optimize an application's throughput and scalability for real-time Web applications. It uses Google V8 JavaScript engine to execute code, and a large percentage of the basic modules are written in JavaScript. Node.js contains a built-in library to allow applications to act as a stand-alone Web server.
Packages and Package Managers
Package: code managed and maintained code with a package management system. Package management system: software that automates installing and updating packages. Deal with what version you have or need, and manages dependencies.
http_parser
Parses http requests and responses. Extracts the following information from HTTP messages: Header fields and values Content-Length Request method Response status code Transfer-Encoding HTTP version Request URL Message body
EventEmitter
Put simply, it allows you to listen for "events" and assign actions to run when those events occur. In Node.js, it's an alternative to deeply nested callbacks. A lot of Node.js methods are run asynchronously, which means that to run code after the method has finished, you need to pass a callback method to the function. Eventually, your code will look like a giant funnel. To prevent this, many Node.js classes emit events that you can listen for. This allows you to organize your code the way you'd like to, and not use callbacks. Many objects in Node.js allow you to listen to and emit events because they are a type of EventEmitter.
Serialize / Deserialize
Serialize: Translating an object into a format that can be stored or transferred. JSON, CSV, & XML are popular. Deserialize is the opposite -- converting the format back into an object.
Web Server Checklist
1) Better ways to organize our code into reusable pieces - modules 2) Ways to deal with files - synchronous/asynchronous data buffering 3) A away to deal with work that takes a long time - asynchronous running code with callbacks, streams dealing with chunks of data 4) The ability to accept requests and send responses in the standard format - http 5) The ability to communicate over the internet - TCP/IP 6) Ways to deal with databases - mysql, mongodb/mongoose, etc.
TCP/IP Protocol
Each computer has an IP (internet protocol) that serves as its identifier. Each computer opens a socket. A socket is where the data flows. We send data structured in a http/ftp/smtp protocol. The protocol for how we actually send the data is TCP (transmission control protocol). The data is split and set as separate packets. Node sees these packets and accepts them as a stream.
Event
Something that happened in our app that we can respond too. 1) System Events (C++ core, libuv) 2) Custom Events (JavaScript core, event emitter)
Full Stack Developer
A developer who knows all the pieces of a software stack and thus can build software by themselves.
Callback
A function passed to another function, which we assume will be invoked at some point. The function 'calls back' invoking the function you gave it.
API Endpoint
A particular URL in a web API. That endpoint (URL) can do multiple things by making choices based on the HTTP request headers.
Protocol
A set of rules that two sides agree to use when communicating. Both the client and server are programmed to understand that particular set of rules.
template engine
A template engine enables you to use static template files in your application. At runtime, the template engine replaces variables in a template file with actual values, and transforms the template into an HTML file sent to the client. This approach makes it easier to design an HTML page. Some popular template engines that work with Express are Jade, Mustache, and EJS. The Express application generator uses Jade as its default, but it also supports several others.
REST
An architectural style for building API's. We decide that HTTP verbs and URLs (nouns) mean something. It's very simple to build basic REST API's with express.
stream & buffer
Buffer: A temporary area of memory that can be used for processing data. Stream: A sequence of data made available over time. Pieces of data eventually combine into a whole. (You "stream" a movie and you can begin watching the movie when enough of the "buffer" has been filled.)
middleware
Code or software that fits between two layers of software. In the case of Express, sitting between the request and the response. Makes it easy to run a specific function for your routes.
pipes/piping
Connecting two streams by writing to one stream what is being read from another. In Node, you pipe from a Readable stream to a Writable stream. Node likes it when we use streams.
environment variables
Global variables specific to the environment (server) our code is living in. Different servers can have different variable settings, and we can access those values in code.
HTTP
Hypertext Transfer Protocol. A conventional set of communication rules for and a format for data being transferred on the web.
Express
Makes it easier to build a web server. "Fast, unopinionated, minimalist web framework for Node.js" unopinionated = allows and trusts the developer to make the right decisions and puts more control in their hands.
Routing
Mapping http requests to content. Whether the actual file exists on the server, or not. When someone requests something I'll stream the content back. And how I deal with the content internally on the server is up to me.
MEAN stack
MongoDB - document database Express - JS framework that makes things like routing, writing APIs, and working with HTTP easier. AngularJS - JS framework for managing code and UI in the browser. Node.js - JS on the server. Handle HTTP requests and responses and lots more.
Asynchronous
More than one process running simultaneously. NodeJS is asynchronous. JavaScript itself is synchronous.
Node Event Loop
Node.js is a single threaded application but it support concurrency via the concepts of events and callbacks. As every API of Node.js are asynchronous and being a single thread, it uses async function calls to maintain the concurrency. Node uses the observer pattern. A Node thread keeps an event loop and whenever any task get completed, it fires the corresponding event which then signals the event listener function to get executed.
Document Object Model (DOM)
Structure browsers use to store and manage web pages. Browsers give the JS engine the ability to manipulate the DOM. The DOM doesn't live in the JS engine. The browser uses the DOM to render the webpage and gives JS the ability to manipulate the DOM and the browser will re-render the page after it's been manipulated.
Template
Text designed to be the placeholder for final text or content after being processed. There's usually some specific template language, so the template system knows how to replace placeholders with real values.
Node Package Manager (NPM)
The largest ecosystem of open source code in history. NPM comes preinstalled with Node.js. NPM is a registry for packages. Anyone can add to NPM.
Semantic Version (SemVer)
Versioning: specifying what version of a set of code this is. The word 'semantic' implies that something conveys meaning. So the version number actually means something. Semantic versioning gives us information by just looking at the version number. You agree to the following protocol for versioning: 1.7.2 = major.minor.patch patch - bug fixes minor - some features added. your code will still work. major - big changes and your code may break.
Port
When a program (Node) is setup on the OS to receive packets from a particular port, it is said that the program is 'listening' to that port. (1) As applied to services running on a computer, a number assigned to a process on a computer so that the process can be found by TCP/IP. Also called a port address or port number. (2) Another name for an I/O address. See also I/O address.
Node.js architecture
https://vimeo.com/76557798
http method
specifies the type of action the request wishes to make. GET, POST, DELETE, and others. Also called verbs.