Advertisement
Guest User

Untitled

a guest
Aug 3rd, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. var express = require('express');
  2. var app = express();
  3. var fs = require('fs');
  4.  
  5. var mysql = require('mysql');
  6. var connection = mysql.createConnection({
  7. host: 'localhost',
  8. user: 'root',
  9. password: 'root',
  10. database: 'projekt',
  11. charset: 'utf8'
  12. });
  13.  
  14. app.use(express.static('../frontend'));
  15.  
  16.  
  17. app.get('/waren', function (req, res) {
  18.  
  19. // connection.query('UPDATE ware SET amount = 3 WHERE product = "Klebestift"')
  20. connection.query("SELECT * FROM ware", function (error, result, fields) {
  21. if (error) throw error;
  22. res.send(result);
  23. variableStart = "var data = ";
  24. QueryLocation = "MyQueryOutput.json";
  25.  
  26.  
  27. fs.writeFile(QueryLocation, variableStart + JSON.stringify(result), function (error) {
  28. if (error) throw error;
  29.  
  30. console.log('Saved Query Output to ' + QueryLocation + ' !');
  31. })
  32. if (error) throw error;
  33.  
  34. });
  35.  
  36. });
  37.  
  38.  
  39. app.listen(3000, function () {
  40. console.log('app listening on port 3000!');
  41. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement