-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
executable file
·43 lines (37 loc) · 993 Bytes
/
Copy pathserver.js
File metadata and controls
executable file
·43 lines (37 loc) · 993 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
32
33
34
35
36
37
38
39
40
41
42
43
var express = require('express');
var fs = require('fs');
var app = express();
app.set('views', __dirname + '/views');
app.set('view engine', 'pug');
app.use(express.static('public'));
var images = [];
var fileFilter = function(file) {
if (file.indexOf(".jpg") > -1) {
return true;
}
return file.indexOf(".JPG") > -1
};
/* scan Images and add them to array */
fs.readdir('./public/images', function(err, items) {
if(err){
console.log(err)
} else {
items.filter(fileFilter).forEach(function(item){
images.push({
'src': 'http://localhost:3000/images/' + item,
'src480': 'http://localhost:3000/images/480/' + item
})
})
}
});
/* call template and display images */
app.get('/', function (req, res) {
res.render("images", {
title: "imagelist",
images: images
});
});
/* start server */
app.listen(3000, function () {
console.log('started server on port 3000')
});