-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathserver.js
More file actions
31 lines (22 loc) · 783 Bytes
/
server.js
File metadata and controls
31 lines (22 loc) · 783 Bytes
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
const express = require('express');
const fetch = require('node-fetch');
const bodyParser = require('body-parser');
const pug = require('pug');
const app = express();
const PORT = process.env.PORT || 3000;
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.set('view engine','pug');
app.use(express.static(__dirname + '/assets'));
app.get('/', (req, res) => {
res.render('index');
});
app.post('/users', async (req, res) => {
const { username } = req.body;
const response = await fetch(`https://api.github.com/users/${username}`);
const data = await response.json();
const profile = pug.compileFile('views/components/profile.pug');
res.send(profile(data));
});
app.listen(PORT);
console.log('root app listening on port: 3000');