-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
48 lines (38 loc) · 1.29 KB
/
Copy pathserver.js
File metadata and controls
48 lines (38 loc) · 1.29 KB
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
44
45
46
47
48
'use strict';
const express = require('express');
const bodyParser = require('body-parser');
const path = require('path');
const request = require('request');
const fs = require('fs');
const app = express();
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());
app.use(express.static(path.join(__dirname, 'src')));
app.set('views', __dirname + '/src/views');
app.engine('html', require('ejs').renderFile);
const flickrApiKey = "YOUR_API_KEY"; //replace this string with your flickr api key
app.get('/getPhotos', function(req, res) {
const url = "https://api.flickr.com/services/rest/?method=flickr.galleries.getPhotos&api_key="
+ flickrApiKey
+ "&gallery_id=72157695356899955&format=json&nojsoncallback=1";
request.get(url, function (error, response, body) {
if (error) {
console.log(error);
res.status(500).send(error);
}
let json = JSON.parse(body);
res.status(201).send(json);
});
});
app.get('/getProducts', function (req, res) {
fs.readFile('products.json', (err, data) => {
if (err) {
res.status(500).send(err);
}
res.status(201).send(data);
});
});
const port = 8000;
app.listen(port, function () {
console.log('app listening to port: ', port);
});