NODE JS
Node is a Javascript runtime built on the Chrome V8 engine
It allows us to run JavaScript on the server
Runtime?
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.
What are the benefits of Node?
- Same team can work on the front end and the back end
- Node is non-blocking. It can do many things at the same time which speaks to its fast speed
- Can easily migrate code from the front end to the back end
- Can work with relational of non-relational DB
- Common data formats (JSON) between the server and client
- Common software tools exist for the server and client
- When writing web applications, view templates can be used on both sides
- Very fast (thanks to V8) and scalable
Best applications for Node
- REST Api - sometimes you may just have a backend serving JSON
- Real Time services ( chat)
- CRUD Applications - shopping cart, blogs, social
- building utilities
- creating microservices
Anything non cpu intensive which would block other things from happening
Node uses V8 Engine
- V8 Engine is used in Chrome & Brave to transpile JS
https://nodejs.dev/learn/the-v8-javascript-engine - Gecko for Firefox
- Webkit for Apple
- Presto for Safari
Node is Built using C++
Node had 3 parts:
- The libuv library
- V8 Engine
- Global Interface
The V8 Engine will transpile our code into C++ which will later be transpiled into Machine Language for the computer to read.

libuv
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

Global Environment
Browser Api
stores methods on Window object
Node
stores methods on Global
object
Node Project Organization
- Node projects can be made up of 100's of files called modules.
- Putting code into one file is unreadable and unmanageable
- We spread our code into these files for organization and readability
- Files are called modules
Modules Meant to have a Single Responsibility
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.
Encapsulation
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
Exports
Object used to transport functions, variables etc to other modules
Let's take a look
module.exports vs exports
Creating a node Project
npm init creates a new node project and a package.json
Creating 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
What is a package.json
- Holds the metadata of your project
- Brains of the whole entity
- List the dependencies needed for your project and their versions
- Holds specific script definitions
- Many other things
What is a package.lock.json
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
What is a node_modules
Holds all the dependency code that we use in our project.
Do not change code in this folder

What is npm?
npm is worlds largest software registry
If you want functionality for something
there is probably a package that does it
Dependencies in Node Projects
3 Kinds
- Global
- Project
- Developer
Node has Native Modules
We require native modules by simply using require and the name of the package
const event = require('events')
Event Emitter
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
File System
The fs module provides a lot of very useful functionality to access and interact with the file system.
const fs = require('fs')
Lets look at some code
NODE
By JD Richards
NODE
- 21