Created
August 9, 2017 20:57
-
-
Save jzrake/05f6736763a6075c81f2b6dd63c4646a to your computer and use it in GitHub Desktop.
A node.js server that uses mathjax to produce an SVG response.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var http = require('http') | |
var qs = require('querystring'); | |
var mj = require("mathjax-node"); | |
var socketio = require('socket.io'); | |
var server = http.createServer(function(req, res) | |
{ | |
req.on('data', function (chunk) | |
{ | |
var equation = qs.parse(chunk.toString('utf8'))['equation']; | |
mj.typeset({math:equation, format:"TeX", svg:true}, function(data) | |
{ | |
res.writeHead(200, {'Content-type': 'text/plain'}); | |
if (data.errors) | |
{ | |
res.end(data.errors.toString('utf8')); | |
} | |
else | |
{ | |
res.end(data.svg); | |
} | |
}); | |
}); | |
}); | |
server.listen(8080, function() | |
{ | |
console.log('Listening at: http://localhost:8080'); | |
}); | |
socketio.listen(server).on('connection', function (socket) {}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment