Last active
August 29, 2015 14:14
-
-
Save treeherder/676b5ff1a12394a04119 to your computer and use it in GitHub Desktop.
twilio server in express
This file contains 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 express = require('express'); | |
var app = express(); | |
app.use(express.logger('dev')); | |
app.use(express.bodyParser()); | |
app.use(app.router); | |
app.post('/upload', function(req, res){ | |
if(req.files.myUpload){ | |
var python = require('child_process').spawn( | |
'python', | |
// second argument is array of parameters, e.g.: | |
["/home/me/pythonScript.py" | |
, req.files.myUpload.path | |
, req.files.myUpload.type] | |
); | |
var output = ""; | |
python.stdout.on('data', function(){ output += data }); | |
python.on('close', function(code){ | |
if (code !== 0) { return res.send(500, code); } | |
return res.send(200, output) | |
}); | |
} else { res.send(500, 'No file found') } | |
}); | |
require('http').createServer(app).listen(3000, function(){ | |
console.log('Listening on 3000'); | |
}); |
This file contains 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 exec = require('child_process').exec; | |
var child = exec('node ./commands/server.js'); | |
child.stdout.on('data', function(data) { | |
console.log('stdout: ' + data); | |
}); | |
child.stderr.on('data', function(data) { | |
console.log('stdout: ' + data); | |
}); | |
child.on('close', function(code) { | |
console.log('closing code: ' + code); | |
}); |
This file contains 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 express = require('express'), | |
bodyParser = require('body-parser'); | |
var app = express(); | |
app.use(bodyParser.urlencoded({ | |
extended: false | |
})); | |
app.post('/ring', function(req, res) { | |
var from = req.body.From, | |
body = req.body.Body; | |
// do whatever | |
// ... | |
res.send(200); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment