SHARE
TWEET

Untitled

a guest May 25th, 2019 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const express = require('express');
  2. const fs = require('fs');
  3. const readdirAsync = require('util').promisify(require('fs').readdir);
  4. const writeFileAsync = require('util').promisify(require('fs').writeFile);
  5.  
  6. const app = express();
  7.  
  8. function generate_random_data(size){
  9.     var chars = 'abcdefghijklmnopqrstuvwxyz'.split('');
  10.     var len = chars.length;
  11.     var random_data = [];
  12.  
  13.     while (size--) {
  14.         random_data.push(chars[Math.random()*len | 0]);
  15.     }
  16.  
  17.     return random_data.join('');
  18. }
  19.  
  20.  
  21. app.use('/sync', (req, res) => {
  22.     const files = fs.readdirSync('./node_modules');
  23.     const files2 = fs.readdirSync('./node_modules/express/lib');
  24.     res.send({answer:'yes'})
  25. });
  26.  
  27. app.use('/async', async (req, res) => {
  28.     const files = await readdirAsync('./node_modules');
  29.     const files2 = await readdirAsync('./node_modules/express/lib');
  30.     res.send({answer:'yes'})
  31. });
  32.  
  33. app.use('/wsync', (req, res) => {
  34.     const data = generate_random_data(10000);
  35.     const files = fs.writeFileSync('./testFileS', data);
  36.     res.send({answer:'yes'})
  37. });
  38.  
  39. app.use('/wasync', async (req, res) => {
  40.     const data = generate_random_data(10000);
  41.     const files = writeFileAsync('./testFileA', data);
  42.     res.send({answer:'yes'})
  43. });
  44.  
  45. app.listen(5555, () => {
  46.   console.log('Listening on port', 5555);
  47. });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top