Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var express = require('express');
- var app = express();
- var fs = require('fs');
- var mysql = require('mysql');
- var connection = mysql.createConnection({
- host: 'localhost',
- user: 'root',
- password: 'root',
- database: 'projekt',
- charset: 'utf8'
- });
- app.use(express.static('../frontend'));
- app.get('/waren', function (req, res) {
- // connection.query('UPDATE ware SET amount = 3 WHERE product = "Klebestift"')
- connection.query("SELECT * FROM ware", function (error, result, fields) {
- if (error) throw error;
- res.send(result);
- variableStart = "var data = ";
- QueryLocation = "MyQueryOutput.json";
- fs.writeFile(QueryLocation, variableStart + JSON.stringify(result), function (error) {
- if (error) throw error;
- console.log('Saved Query Output to ' + QueryLocation + ' !');
- })
- if (error) throw error;
- });
- });
- app.listen(3000, function () {
- console.log('app listening on port 3000!');
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement