# Express
---
- What is express
- How to to install it
- How to use it
- Live Coding!!!!!!
---
## What is express?
Express is a minimal and flexible Node.js web application framework that provides a robust set of features for web and mobile applications.
---
## The install
```
npm install express
```
---
## Basic Server Setup
```
const express = require('express');
const app = express();
const PORT = 3000;
app.listen(PORT, localhost, ()=> {
console.log(`Server listening on port ${PORT}`)
})
```
---
## Usage and Syntax
- GET
- POST
---
## GET
```
app.get('/route', (req, res)=>{
res.send('Hello World, How is the world today?')
// or
res.json('Hello World, How is the world today?')
})
```
---
## POST
```
app.post('/route', (req, res)=>{
res.send({
status: 200,
ok: true,
msg:'Hello World, How is the world today?'
})
})
```
---
## Middleware
Middleware are functions that have access to the request and response objects. It also has access the the `next()` middleware function
*side note: `next()` is used to continue the on the next middleware call in the repsonse-sequence. To learn more about next visit the [using middleware](https://expressjs.com/en/guide/using-middleware.html) section in the express docs.*
---
## Middleware Usage
```
app.use(/*insert middle ware action here*/)
```
---
## Examples.
```
const express = require('express');
const bodyParser = require("body-parser");
app.use(express.static(__dirname + '/public'));
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
```
---
# Lets Go Live
---
## Axios
```
https://cdnjs.cloudflare.com/ajax/libs/axios/0.9.1/axios.js
```
---
## Templating with express
```
npm install express-es6-template-engine
```
---
# Usage
```
const es6Renderer = require('express-es6-template-engine');
app.engine('html', es6Renderer);
app.set('views', 'templates');
app.set('view engine', 'html');
app.get('/route', (req,res)=>{
res.render()
})
```
---
{"metaMigratedAt":"2023-06-17T02:21:18.021Z","metaMigratedFrom":"Content","title":"Express","breaks":true,"contributors":"[{\"id\":\"5e29e175-4809-4add-a41e-e8982dab52a9\",\"add\":2534,\"del\":501}]"}