Skip to content

Instantly share code, notes, and snippets.

@yousfiSaad
Created October 26, 2015 11:31
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 yousfiSaad/d2c3b34dc4542d26c321 to your computer and use it in GitHub Desktop.
Save yousfiSaad/d2c3b34dc4542d26c321 to your computer and use it in GitHub Desktop.
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