Advertisement
Guest User

Untitled

a guest
Jul 19th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const express = require('express');
  2. const os = require('os');
  3. const fs = require('fs');
  4. const app = express();
  5. const port = 8888;
  6.  
  7. let body = '';
  8.  
  9. app.post('/file', (req, res) => {
  10.  
  11.     body = '';
  12.     req.on('data', data => {
  13.         body += data;
  14.     });
  15.  
  16.     req.on('end', () => {
  17.         let dataArray = body.split(os.EOL);
  18.         let content = dataArray.slice(dataArray.indexOf('') + 1, -2).join(os.EOL);
  19.         fs.writeFile('file.css', content, err => {
  20.             if (err) throw err;
  21.             console.log('File has been saved!');
  22.         });
  23.     });
  24.    
  25.     res.end('ok');
  26. })
  27.  
  28.  
  29. app.listen(port, () => console.log(`Server has been started on port ${port}!`));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement