Advertisement
Guest User

Untitled

a guest
Jul 5th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.98 KB | None | 0 0
  1. var express = require('express');
  2. var app = express();
  3. var path = require('path');
  4. var router = express.Router();
  5. var data = require('./data/jsonData');
  6. var createDatabase = require('./data/db');
  7. var careateTable = require('./data/createTable');
  8. var insert = require('./data/insert');
  9. var bodyParser = require('body-parser');
  10. var select = require('./data/select');
  11.  
  12.  
  13. app.use(express.static(path.join(__dirname, 'www')));
  14. app.use(express.static(path.join(__dirname, 'form')));
  15. app.use(bodyParser());
  16. app.get('/' , function (req , res) {
  17. res.sendFile(path.join(__dirname + '/www/index.html'));
  18. });
  19.  
  20. app.get('/data' ,function (req , res) {
  21. res.json(data);
  22. });
  23. app.get('/form' ,function (req , res) {
  24. res.sendFile(path.join(__dirname + '/form/index.html'));
  25. });
  26. app.post('/form' ,function (req , res) {
  27. console.log(req.body.user);
  28. console.log(req.body.password);
  29. insert.insertModule(req.body.user , req.body.password);
  30. res.sendFile(path.join(__dirname + '/www/index.html'));
  31. });
  32. app.get('/show' , function (req , res) {
  33. var i ;
  34. select.select( function (err, results) {
  35. if (err == 'error') {
  36. console.log(err);
  37. } else {
  38. console.log(results);
  39. res.send(results.username);
  40. }
  41. });
  42.  
  43. });
  44.  
  45. app.listen(3000);
  46. console.log("App is listning on port 3000");
  47.  
  48. var mysql = require('mysql');
  49. var con = mysql.createConnection({
  50. host: "localhost",
  51. user: "root",
  52. password: "",
  53. database: "NodeDataBase"
  54. });
  55. con.connect(function (err) {
  56. if (err) throw err;
  57. console.log("Connected!");
  58. });
  59.  
  60. module.exports = {
  61. select: function (callback) {
  62. var sql = "SELECT username , password FROM login ";
  63. con.query(sql, function (err, result , fields) {
  64. if (err) {
  65. callback("error", err)
  66. } else {
  67. callback("success", result)
  68. }
  69. });
  70. }
  71. }
  72.  
  73. <!doctype html>
  74. <html ng-app>
  75. <head>
  76. <title>My AngularJS App</title>
  77. <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"></script>
  78. </head>
  79. <body>
  80. <div ng-controller="MyCtrl">
  81. <table>
  82. <thead>
  83. <tr>
  84. <th>
  85. <p>Name</p>
  86. </th>
  87. </tr>
  88. </thead>
  89. <tbody>
  90. <tr ng-repeat="user in users">
  91. <td>
  92. <p>{{user}}</p>
  93. </td>
  94. </tr>
  95. </tbody>
  96. </table>
  97. </div>
  98. <script>
  99. var myApp = angular.module('myApp',[]);
  100. function MyCtrl($scope, $http) {
  101. //This method will call your server, with the GET method and the url /show
  102. $http.get("http://localhost:3000/show").then(function(success){
  103. if(success.data.length>0)
  104. {
  105. $scope.users=success.data;
  106. }
  107. });
  108. }
  109. </script>
  110. </body>
  111. </html>
  112.  
  113. var express = require('express');
  114. var app = express();
  115.  
  116. require('json-response');
  117.  
  118. app.get('/', function(req, res){
  119. res.ok({foo: 'bar'}, 'hello world');
  120. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement