SHARE
TWEET

Express: Koneksi ke MYSQL & Baca Data

stevennathaniel Jun 29th, 2016 150 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * Created by StevenNathaniel on 29-Jun-16.
  3.  */
  4.  
  5. var express = require('express');
  6.  
  7. var app = express();
  8.  
  9. var mysql = require('mysql');
  10.  
  11. var path = require('path');
  12.  
  13. var pug = require('pug');
  14.  
  15. var bodyParser = require('body-parser');
  16.  
  17.  
  18. app.set('view engine','pug');
  19.  
  20. app.set('views',__dirname + '/views');
  21.  
  22. app.use('/static',express.static('public'));
  23.  
  24.  
  25. var koneksi = mysql.createConnection({
  26.     host:'localhost',
  27.     user:'root',
  28.     password:''
  29. });
  30.  
  31. app.get('/',function(req,res) {
  32.     koneksi.query('USE latihan');
  33.     koneksi.query('SELECT * FROM pegawai', function(err,rows,fields) {
  34.         if (err) throw err;
  35.         console.log(JSON.stringify(rows));
  36.         res.send(JSON.stringify(rows));
  37.     });
  38. });
  39.  
  40. app.listen(8080);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top