---
# System prepended metadata

title: Node
tags: [curriculum]

---

---

tags: curriculum

---

# Node


---

## What is Node?
:bird:

Node is a way of running JavaScript code outside of a web browser, from your computer's command line.

---

## What is Node for? :bird:
Lots of things. Two standout uses are:

- writing web servers
- writing JavaScript that writes JavaScript

We'll focus on the first. Later in the course, when you learn React, you'll start doing the second.

---

## What is a server? :monkey: 

---
The server is the computer that a client talks to, or the program on the serverside computer.

---

![](https://i.imgur.com/8Jam0cZ.png =1000x)

- your computer, the client, sends a GET __request__ to the server
- The server __responds__ with HTML
- If necessary, the client makes more GET requests, e.g. for CSS.


---

### Why do we need servers? :monkey: 

---

* Handle manipulation of data in the database

* File manipulation

* Authentication

* Secret Logic

These are I/O (Input/Output) operations.
They often take time to execute.

---

## What makes Node special? :bird: 

There are lots of ways of writing server code. Node is particularly good because:

- It is asynchronous and non-blocking (faster than other languge offerings, like Python + Ruby)
- It's written in the same language as frontend code, JavaScript.

---

## Structure of a project - package.json :bird: 

- A Node project contains a package.json file. 
- This is like the table of contents of your program. 
- It is automatically generated by a tool called NPM (or Yarn in a project with yarn-lock.json)
- Create a package.json with the command `npm init -y` (or remove `-y`, which stands for 'yes', for a setup questionnaire)

---

## NPM  :monkey: 
- NPM is a 'package manager' and a website (npmjs.com).
- with the commands `npm i <name>` and `npm i -D <name>` you can install bits of pre-written JavaScript ('modules'/'packages') from npmjs.

---

- The name will get added to your package.json in `dependencies`. 
- The code itself will get added to a node_modules folder. 
- You can then import the module code in your project files.

---

## Kinds of modules :monkey: 
In Node there are three kinds of modules:

- third-pary modules (the kind you install with NPM)
- Node core modules (parts of Node which are available in every project without any downloading, but which you have to import in your file to use)
- local modules (code you've written in one file which you want to use in another file)

---

### Super useful links  🔗

The Art of Node
https://github.com/maxogden/art-of-node#the-art-of-node

Dan's super simple Node server:
https://github.com/sofer/sssk

---