Created
October 26, 2015 11:31
-
-
Save yousfiSaad/d2c3b34dc4542d26c321 to your computer and use it in GitHub Desktop.
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(); | |
var bodyParser = require('body-parser'); | |
var fs = require('fs'); | |
var beautify_html = require('js-beautify').html; | |
app.use(bodyParser.json()); | |
app.use(bodyParser.urlencoded()); | |
app.use(bodyParser.urlencoded({ extended: true })); | |
app.post('/file', function(req, res){ | |
var fileContent = beautify_html(req.body.fileContent); | |
fs.writeFile(__dirname + '/www/' + req.body.fileName , fileContent, function(err) { | |
if(err) { | |
return console.log(err); | |
} | |
res.send('http://localhost:3000/www/' + req.body.fileName); | |
}); | |
}); | |
app.use('/www', express.static(__dirname + '/www')); | |
var server = app.listen(3000, function () { | |
var host = server.address().address; | |
var port = server.address().port; | |
console.log('App listening at http://%s:%s', host, port); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment