Skip to content

Instantly share code, notes, and snippets.

@jzrake
Created August 9, 2017 20:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jzrake/05f6736763a6075c81f2b6dd63c4646a to your computer and use it in GitHub Desktop.
Save jzrake/05f6736763a6075c81f2b6dd63c4646a to your computer and use it in GitHub Desktop.
A node.js server that uses mathjax to produce an SVG response.
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