Node is a Javascript runtime built on the Chrome V8 engine
It allows us to run JavaScript on the server
Runtime describes software/instructions that are executed while your program is running, especially those instructions that you did not write explicitly, but are necessary for the proper execution of your code.
Anything non cpu intensive which would block other things from happening
Node had 3 parts:
The V8 Engine will transpile our code into C++ which will later be transpiled into Machine Language for the computer to read.
library written in C++ that does that heavy lifting handling the asynchronicity of node making it appear multi-threading and non-blocking as well as turning code into machine language
Browser Api
stores methods on Window object
Node
stores methods on Global
object
Single Responsibility Theory Definition:
every module, class or function in a computer program should have responsibility over a single part of that program's functionality, which it should encapsulate.
the bundling of data, along with the methods that operate on that data, into a single unit. ... Encapsulation can be used to hide both data members and data functions or methods associated with an instantiated class or object
Object used to transport functions, variables etc to other modules
Let's take a look
module.exports vs exports
npm init creates a new node project and a package.json
//In your terminal
mdkir <name of directory> & cd <name of directory>
npm init //creates package.json
//click Enter For Questions
npm install
Sometimes versions of different packages change and do not work well together. package.lock.json Keeps a record of the versions of the dependencies you use
Holds all the dependency code that we use in our project.
Do not change code in this folder
npm is worlds largest software registry
If you want functionality for something
there is probably a package that does it
We require native modules by simply using require and the name of the package
const event = require('events')
Node runs base on events and many are built into node's base code
We use an Event Emitter on the events object to create custom events
Think of events like you did with the DOM
When you see things like chat apps and/or push notifications, and many other things, they are based on the event emitter
The fs module provides a lot of very useful functionality to access and interact with the file system.
const fs = require('fs')