-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
33 lines (28 loc) · 963 Bytes
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
require('dotenv').config();
const express = require('express');
const app = express();
const fetch = (...args) =>
import('node-fetch').then(({ default: fetch }) => fetch(...args));
app.get('/', (req, res) => {
res.sendFile(__dirname + '/static/index.html');
});
app.get('/generate', async (req, res) => {
const url = `https://api.api-ninjas.com/v1/passwordgenerator?length=${req.query.length}&exclude_numbers=${req.query.excludeNumbers}&exclude_special_chars=${req.query.excludeSpecialChars}`;
const options = {
method: "GET",
headers: {
"X-Api-Key": process.env.API_KEY
}
}
try {
const resu = await fetch(url, options);
const json = await resu.json();
res.send(json["random_password"]);
} catch (err) {
console.log(err);
res.send("Error generating password.");
}
});
app.listen(3000, () => {
console.log('Server is running on port 3000');
});