Pro_Unit

WriteFile

May 26th, 2020
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const http = require( 'http' );
  2. const url = require( 'url' );
  3. const fs = require( 'fs' )
  4.  
  5. const hostname = '62.109.12.220';
  6. const port = 3000;
  7.  
  8. const server = http.createServer( ( req, res ) => {
  9.  
  10.     res.statusCode = 200;
  11.  
  12.     const url_parts = url.parse( req.url, true );
  13.  
  14.     const query = url_parts.query;
  15.  
  16.     console.log( 'YOLO' );
  17.  
  18.     res.setHeader( 'Content-Type', 'application/json' );
  19.  
  20.     var jsonQuery = JSON.stringify( query );
  21.  
  22.     fs.writeFileSync( "Queries/query.json", jsonQuery );
  23.  
  24.     console.log( jsonQuery );
  25.  
  26.     res.end( jsonQuery );
  27. } );
  28.  
  29. server.listen( port, hostname, () => {
  30.     console.log( `Server running at http://${hostname}:${port}/` );
  31. } );
Add Comment
Please, Sign In to add comment