forked from COGS121/InstagramAppExample
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
52 lines (46 loc) · 1.54 KB
/
app.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//dependencies for each module used
var express = require('express');
var http = require('http');
var path = require('path');
var handlebars = require('express3-handlebars');
var app = express();
//route for hashtag
var hashtag = require('./routes/hashtag');
var index = require('./routes/index');
//database setup
var mongoose = require('mongoose');
mongoose.connect(process.env.MONGOLAB_URI || 'mongodb://localhost/instagramexample');
//Configures the Template engine
app.engine('handlebars', handlebars());
app.set('view engine', 'handlebars');
app.set('views', __dirname + '/views');
app.use(express.static(path.join(__dirname, 'public')));
app.use(express.bodyParser());
//routes
app.get('/', index.view);
app.get('/hashtag', function (req, res) {
res.render('hashtag');
})
app.post('/hashtag', hashtag.getHashtag);
app.post('/save', hashtag.saveFavorites);
app.post('/delete', index.deleteImage);
//set environment ports and start application
app.set('port', process.env.PORT || 3000);
http.createServer(app).listen(app.get('port'), function(){
console.log('Express server listening on port ' + app.get('port'));
});
//load environment variables
var dotenv = require('dotenv');
dotenv.load();
//add instagram api setup
var ig = require('instagram-node-lib');
ig.set('client_id', process.env.instagram_client_id);
ig.set('client_secret', process.env.instagram_client_secret);
ig.tags.info({
name: 'sushi',
complete: function(data) {
console.log(data);
}
});
//export ig as a parameter to be used by other methods that require it.
exports.ig = ig;