-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
57 lines (45 loc) · 1.58 KB
/
server.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
53
54
55
56
57
var express = require('express');
var mongoose = require('mongoose');
var http = require('http');
var path = require('path');
var routes = require('./server/routes');
var jsdom = require("jsdom");
var app = express();
app.engine('html', require('hogan-express'));
app.set('view options', {layout: true});
app.set('layout', 'layout');
app.enable('view cache');
app.set('port', process.env.PORT || 3000);
app.set('view engine', 'html');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(path.join(__dirname, 'www/globalnews')));
app.use('/bower_components',express.static(path.join(__dirname, 'bower_components')));
var index = "../www/globalnews/index";
app.get('/', function(req, res){
res.render(index);
});
mongoose.connect('mongodb://newsreaderpolitics:[email protected]:55689/newsreaderpolitics');
var News = mongoose.model('News', { name: String });
jsdom.env({
url: "http://www.unian.ua/",
scripts: ["http://code.jquery.com/jquery.js"],
done: function (errors, window) {
var $ = window.$;
console.log("HN Links");
$(".left_top ul.main_all_news li a ").each(function() {
var text = $(this).text()
console.log(" -", text);
/////
var kitty = new News({ name: text });
kitty.save();
});
}
});
routes.initialize(app);
http.createServer(app).listen(app.get('port'), function(){
console.log('Express server listening on port ' + app.get('port'));
});