Advertisement
Guest User

Untitled

a guest
Apr 8th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. [{ "id":"1", "text":"learn angular", "done":true },
  2. { "id":"2", "text":"build an angular app", "done":false}]
  3.  
  4. var fs = require('fs');
  5. var serverUrl = 'localhost';
  6. var port = 3000;
  7. var path = require('path');
  8. var express = require('express');
  9. var app = express();
  10. var http = require('http').Server(app);
  11. var mysql = require('mysql');
  12. var bodyParser = require('body-parser');
  13. var methodOverride = require('method-override');
  14. app.use(bodyParser.json()); // parse application/json
  15. app.use(bodyParser.json({ type: 'application/vnd.api+json' }));
  16. app.use(bodyParser.urlencoded({ extended: true }));
  17. app.use(methodOverride('X-HTTP-Method-Override'));
  18. app.use(express.static(__dirname + '/public'));
  19. require('./app/routes')(app); // pass our application into our routes
  20. app.get('/', function(req, res){
  21. res.sendfile('public/index.html');
  22. });
  23.  
  24. var connection = mysql.createConnection({
  25. host : 'localhost',
  26. user : 'root',
  27. password : '',
  28. database : 'todos',
  29. });
  30.  
  31. connection.connect();
  32.  
  33. app.get('/',function(request,response){
  34. connection.query('SELECT * FROM todos', function(err, rows, fields, res)
  35.  
  36. {
  37. console.log('Connection result error '+err);
  38. console.log('no of records is '+rows.length);
  39. response.writeHead(200, { 'Content-Type': 'application/json'});
  40. response.end(JSON.stringify(rows));
  41. });
  42.  
  43. app.set('port', 3000);
  44.  
  45. http.listen(port, function(){
  46. console.log('listening on: ' + app.get('port'));
  47. });
  48.  
  49. exports = module.exports = app;
  50.  
  51. <!doctype html>
  52. <html lang="en">
  53. <head>
  54. <meta charset="UTF-8">
  55. <base href="/">
  56.  
  57. <title></title>
  58.  
  59. <!-- CSS -->
  60.  
  61. <!-- JS -->
  62.  
  63. <!-- ANGULAR CUSTOM -->
  64. </head>
  65.  
  66. <body ng-app="App" ng-controller="Controller">
  67. <div class="someClass">
  68. <table>
  69. <tr>
  70. <th>id</th>
  71. <th>text</th>
  72. <th>done</th>
  73. </tr>
  74. <tr ng-repeat="todo in todos">
  75. <td>{{todo.id}}</td>
  76. <td>{{todo.text}}</td>
  77. <td>{{todo.done}}</td>
  78. </tr>
  79. </table>
  80. <div>
  81. </body>
  82. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement