Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var express = require('express');
- var app = express();
- var path = require('path');
- var router = express.Router();
- var data = require('./data/jsonData');
- var createDatabase = require('./data/db');
- var careateTable = require('./data/createTable');
- var insert = require('./data/insert');
- var bodyParser = require('body-parser');
- var select = require('./data/select');
- app.use(express.static(path.join(__dirname, 'www')));
- app.use(express.static(path.join(__dirname, 'form')));
- app.use(bodyParser());
- app.get('/' , function (req , res) {
- res.sendFile(path.join(__dirname + '/www/index.html'));
- });
- app.get('/data' ,function (req , res) {
- res.json(data);
- });
- app.get('/form' ,function (req , res) {
- res.sendFile(path.join(__dirname + '/form/index.html'));
- });
- app.post('/form' ,function (req , res) {
- console.log(req.body.user);
- console.log(req.body.password);
- insert.insertModule(req.body.user , req.body.password);
- res.sendFile(path.join(__dirname + '/www/index.html'));
- });
- app.get('/show' , function (req , res) {
- var i ;
- select.select( function (err, results) {
- if (err == 'error') {
- console.log(err);
- } else {
- console.log(results);
- res.send(results.username);
- }
- });
- });
- app.listen(3000);
- console.log("App is listning on port 3000");
- var mysql = require('mysql');
- var con = mysql.createConnection({
- host: "localhost",
- user: "root",
- password: "",
- database: "NodeDataBase"
- });
- con.connect(function (err) {
- if (err) throw err;
- console.log("Connected!");
- });
- module.exports = {
- select: function (callback) {
- var sql = "SELECT username , password FROM login ";
- con.query(sql, function (err, result , fields) {
- if (err) {
- callback("error", err)
- } else {
- callback("success", result)
- }
- });
- }
- }
- <!doctype html>
- <html ng-app>
- <head>
- <title>My AngularJS App</title>
- <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"></script>
- </head>
- <body>
- <div ng-controller="MyCtrl">
- <table>
- <thead>
- <tr>
- <th>
- <p>Name</p>
- </th>
- </tr>
- </thead>
- <tbody>
- <tr ng-repeat="user in users">
- <td>
- <p>{{user}}</p>
- </td>
- </tr>
- </tbody>
- </table>
- </div>
- <script>
- var myApp = angular.module('myApp',[]);
- function MyCtrl($scope, $http) {
- //This method will call your server, with the GET method and the url /show
- $http.get("http://localhost:3000/show").then(function(success){
- if(success.data.length>0)
- {
- $scope.users=success.data;
- }
- });
- }
- </script>
- </body>
- </html>
- var express = require('express');
- var app = express();
- require('json-response');
- app.get('/', function(req, res){
- res.ok({foo: 'bar'}, 'hello world');
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement