Guest User

Untitled

a guest
Apr 25th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. this.http.get('http://localhost:8080').subscribe(data => {
  2. console.log(data);
  3. });
  4.  
  5. var mysql = require('mysql');
  6. var con = mysql.createConnection({
  7. host: "localhost",
  8. user: "root",
  9. password: "root",
  10. database: "mydb"
  11. });
  12.  
  13. http.createServer(function (req, res) {
  14. res.writeHead(200, {'Content-Type': 'text/plain'});
  15. con.connect(function(err) {
  16. if (err){
  17. res.write(err);
  18. res.end();
  19. console.log(err);
  20. } else {
  21. con.query("SELECT * FROM minister", function (err, result) {
  22. if (err) {
  23. res.write(err);
  24. res.end();
  25. console.log(err);
  26. }
  27. else {
  28. res.write(JSON.stringify(result));
  29. res.end();
  30. }
  31. });
  32. }
  33. })
  34. }).listen(8080);
Add Comment
Please, Sign In to add comment