-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
28 lines (21 loc) · 817 Bytes
/
index.js
File metadata and controls
28 lines (21 loc) · 817 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
const express = require('express');
const readdir = require('fs').readdir;
const getImages = () => { readdir('./images/images', (err, files) => {console.log(files);return files})};
const exec = require('child_process').exec;
const app = express();
app.use(express.static('./'));
function choice(choices) {
var index = Math.floor(Math.random() * choices.length);
return choices[index];
}
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
app.get('/', (req, res) => {
const images = readdir('./images/images', (_err, files) => {
var randomImage = choice(files);
res.send(`<img src=/images/images/${randomImage}>`);
exec('node hash-gen.js');
});
});
app.listen(8080, () => {console.log('Server is running on port http://127.0.0.1:8080')});