-
Notifications
You must be signed in to change notification settings - Fork 4
/
app.js
48 lines (37 loc) · 1023 Bytes
/
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
/**
* Module dependencies.
*/
var express = require('express'),
app = express.createServer(),
io = require('socket.io').listen(app),
ejs = require('ejs'),
os = require('os');
var prev = 0
var curr = 0
// Configuration
app.configure(function(){
app.register('.html',require('ejs'));
app.set('views', __dirname + '/views');
app.set('view engine', 'html');
app.use(app.router);
app.use(express.bodyParser());
app.use(express.static(__dirname + '/public'));
});
io.configure(function() {
io.set('log level', 1);
});
io.of('/data').on('connection',function(socket){
socket.emit('hello',{ data: 'hello'});
socket.on('received',function(data){
var value = os.loadavg()[0];
socket.emit('send',{ data: value});
});
});
// Routes
app.get('/', function(req, res){
res.render('index', {
title: 'hello'
});
});
app.listen(3000);
console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env);