-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnb.js
More file actions
28 lines (24 loc) · 788 Bytes
/
nb.js
File metadata and controls
28 lines (24 loc) · 788 Bytes
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
var fs = require('fs');
var app = require('express')();
const exec = require('child_process').exec;
function execute(command, callback) {
exec(command, (error, stdout, stderr) => {
if(error) {
console.log(error)
}
callback(stdout);
});
};
app.get('/preview', function (req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
execute('ipython nbconvert --to html sample.ipynb', (output) => {
console.log(output)
var html = fs.readFileSync('./sample.html', 'utf8');
res.status(200).send(html);
});
})
const PORT = 5000;
app.listen(PORT, () => {
console.log(`server running on port ${PORT}`)
});