Guest User

Untitled

a guest
Dec 16th, 2018
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. var http = require('http'),
  2. mysql = require("mysql");
  3. var connection = mysql.createConnection({
  4. user: "root",
  5. password: "",
  6. database: "db_name"
  7. });
  8. http.createServer(function (request, response) {
  9. request.on('end', function () {
  10. connection.query('SELECT * FROM your_table;', function (error, rows, fields) {
  11. response.writeHead(200, {
  12. 'Content-Type': 'x-application/json'
  13. });
  14. response.end(JSON.stringify(rows));
  15. });
  16. });
  17. }).listen(8080);
Add Comment
Please, Sign In to add comment