debian
Installation
-
apt update
-
apt install nodejs npm
-
node -v
-
npm -v
-
cd /var/www/
-
mkdir hello_api
-
npm install express
Option 1
-
vi salut.js
- Write the following in that file:
const express = require('express')
const rateLimit = require('express-rate-limit')
const PORT = 5000
const app = express()
const limiter = rateLimit({
windowMs: 5000, // 5 second
max: 1, // Limit each IP to 1 requests per windowMs
message: "TOO MANY REQUEST!!!"
})
// To always use it
//app.use(limiter)
app.get('/', limiter, (req, res) => res.status(200).send('Salut!\n'))
app.get('/bonjour', limiter, (req, res) => res.status(200).send('Bonjour!\n'))
app.listen(PORT, () => console.log(`Listening on port ${PORT}!`))
-
node ./salut.js
-
apt install curl
-
curl http://localhost:5000
-
curl http://localhost:5000/bonjour
Option 2
-
vi hello.js
- Write the following in that file:
#!/usr/bin/env node
const express = require('express')
const app = express()
app.get('/', (req, res) => res.send('Hello world!\n'))
app.listen(5000, () => console.log('Listening on port 5000!'))
-
chmod +x ./hello.js
-
./hello.js
-
curl http://localhost:5000
-
sudo apt update
-
sudo apt install php libapache2-mod-php
-
sudo systemctl restart apache2