-
Notifications
You must be signed in to change notification settings - Fork 64
/
index.js
44 lines (33 loc) · 1.01 KB
/
index.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
var express = require('express');
var app = express();
var server = require('https').createServer(app);
var io = require('socket.io')(server);
var fs = require('fs');
var exec = require('child_process').exec;
var child;
app.use(express.static(__dirname + '/node_modules'));
app.get('/', function(req, res,next) {
res.sendFile(__dirname + '/index.html');
});
io.on('connection', function(client) {
console.log('Client connected...');
client.on('join', function(data) {
//console.log(data);
var stream = fs.createWriteStream("out.js");
stream.once('open', function(fd) {
stream.write(data);
stream.end();
child = exec("node out.js", function (error, stdout, stderr) {
//res.writeHead(200, {'Content-Type': 'text/plain'});
//console.log('stderr: ' + stderr);
if (error !== null) {
client.emit('output', stderr);
}
else
client.emit('output', stdout);
});
});
//run and send output
});
});
server.listen(4000);