Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. ```javascript
  2.  
  3. const express = require('express');
  4. const mysql = require('mysql');
  5. const db = mysql.createConnection({
  6. host: 'localhost',
  7. user: 'root',
  8. password: '',
  9. database: 'test'
  10. })
  11. db.connect((err) => {
  12. if (err) throw err;
  13. });
  14. const app = express();
  15.  
  16. process.on('uncaughtException', function() {
  17. console.log('error loh gan')
  18. });
  19.  
  20. app.get('/api/nama/:id', function (req, res) {
  21. let id = req.params.id;
  22. let sql = 'select * from User order by name';
  23. let query = db.query(sql, function (err, result) {
  24. if (err) {
  25. throw err;
  26. console.log(err);
  27. };
  28. res.send(result);
  29.  
  30. });
  31. });
  32.  
  33. app.get('*',function(req,res){
  34. res.send('no one');
  35. })
  36.  
  37. app.listen(3000, () => {
  38. console.log('app runing on port 300 ...')
  39. })
  40.  
  41. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement