Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [{ "id":"1", "text":"learn angular", "done":true },
- { "id":"2", "text":"build an angular app", "done":false}]
- var fs = require('fs');
- var serverUrl = 'localhost';
- var port = 3000;
- var path = require('path');
- var express = require('express');
- var app = express();
- var http = require('http').Server(app);
- var mysql = require('mysql');
- var bodyParser = require('body-parser');
- var methodOverride = require('method-override');
- app.use(bodyParser.json()); // parse application/json
- app.use(bodyParser.json({ type: 'application/vnd.api+json' }));
- app.use(bodyParser.urlencoded({ extended: true }));
- app.use(methodOverride('X-HTTP-Method-Override'));
- app.use(express.static(__dirname + '/public'));
- require('./app/routes')(app); // pass our application into our routes
- app.get('/', function(req, res){
- res.sendfile('public/index.html');
- });
- var connection = mysql.createConnection({
- host : 'localhost',
- user : 'root',
- password : '',
- database : 'todos',
- });
- connection.connect();
- app.get('/',function(request,response){
- connection.query('SELECT * FROM todos', function(err, rows, fields, res)
- {
- console.log('Connection result error '+err);
- console.log('no of records is '+rows.length);
- response.writeHead(200, { 'Content-Type': 'application/json'});
- response.end(JSON.stringify(rows));
- });
- app.set('port', 3000);
- http.listen(port, function(){
- console.log('listening on: ' + app.get('port'));
- });
- exports = module.exports = app;
- <!doctype html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <base href="/">
- <title></title>
- <!-- CSS -->
- <!-- JS -->
- <!-- ANGULAR CUSTOM -->
- </head>
- <body ng-app="App" ng-controller="Controller">
- <div class="someClass">
- <table>
- <tr>
- <th>id</th>
- <th>text</th>
- <th>done</th>
- </tr>
- <tr ng-repeat="todo in todos">
- <td>{{todo.id}}</td>
- <td>{{todo.text}}</td>
- <td>{{todo.done}}</td>
- </tr>
- </table>
- <div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement