Node Class Notes

Node Class Notes

Node.js

NodeExamples by Tom (see datalogger, encryption, ExpressIntro(this example!), Conn Dev Client, proxyServer.js): Embed GitHubEmbed GitHub

/NodeExamplesTom/NodeWithNginx/proxy-server.js

Node.js is simply running JavaScript on the terminal as opposed to in the browser. Node.js is to JS what Arduino IDE is to C++.

Express → library used specifically to ???????????.

Makes a WebServer in 4 lines of code.

What are these lines of code doing

Requesting from the Operating system to a particular port

will listen to incoming requests on that port

will listen specifically to HTTP formatted requests.

server.js is the actual program

package.json describes the program’s dependencies. Some programs use manifest.js

public > index.html

node_modules

  • Folder should only be removed from GitHub, not to spam their servers.
  • But also these libraries are installed with npm install - list is read from package.json.

If we were using LiveServer, Express, npm ——— all these are programs that serve files.

Most basic way of creating a server in terminal

mkdir newProject
cd newProject
touch script.js
code script.js // Add console.log("Hi there!")
node script.js

Create project with npm init

Nginx / VPS (Node with Nginx - see script under examples)

Nginx is the gateway for all these microservices. Responds to static file requests.

By having a single gateway, Nginx within the port (and IP address && remote access

If Nginx dies, another port is supporting this.

Nginx and Node communicate

body-parser

Remote sessions between two hosts - what governs those? Typically we have our session open for discrete requests

node proxy

ps -a to see all processes we’re running.

man ps manual for ps command

If we kill the terminal, we kill the process that terminal was running.

pm2

PM2 list → program which runs various scripts as constant services.

There various process into a service.

What separates a process and a service?

syscontrols for more experienced programmers

Q: what is

To make a Post request

Option #1: curl -X POST “https://tigoe.net/garden/data?hello’

Option #2: make an input element, event listener,

I’m now realizing I get excited about different protoboards like i do about

TrafficCams host didn’t want to

Button triggers GET request.

Q: Tom was showing available routes and a process shutting down everythiung w no route?

/TODO

Book time w Tom

Ask kezia about jpg decoding.

API

Success with the assignment

Comfortable with APIs and can describe why.

PUT requests.

API results very complex and very

2 part files that are linked: download metadata + file itself.

Where does API call from?

Time it takes for processor to send to card.

Middleman host that only takes from data what is needed.

Co-processor + Side-processor.

Anything with an operating

Co-processors: Local + server.

Tom’s lab

Tom called each program in his Mac a process. Refers back to the kill process / Application but also to the idea that each terminal session is an instance and therefore running a process. Any process can eventually be scaled up to an application.

To think about —- how many processes do I have running as a person?