How to get data from mLab using mongoDb and display into HTML page, using javascript, node.js, express -


i developing web app stores data in mlab , want display data onto html page dropdown menu select player name...

here html...

 <table>   <tr rowspan="10">     <th ><select name="sport" required>         <option value="">please choose player:</option>         <option value="soccer">player1</option>         <option value="football">player2</option>         <option value="hurling">player3</option>         <option value="running">player4</option>       </select></th>       </tr>       </table> 

here .js code..

'use strict'; var express = require('express'); var app = express();  var _ = require('lodash'); var user = require('./user_model'); var player = require('./player_model'); var config = require('../../config/'); var path = require('path');  // list of users exports.index_user = function(req, res) { // connect db user.find(function (err, users) {              if(err) { return handleerror(res, err); }              return res.json(200, users);              });  };  //get list of games   exports.index_player = function(req,res){   player.find(function (err, routes) {             if(err) { return handleerror(res, err); }             return res.json(200, routes);             });      } 

this app.js

'use strict';  // set default node environment development process.env.node_env = process.env.node_env || 'development';  var mongoose = require('mongoose'); var config = require('./config/'); var express = require('express'); var bodyparser = require('body-parser'); //create routing object var user = require('./api/users/index');   //create express app var app = express();  // connect database mongoose.connect(config.mongo.uri, config.mongo.options);  //configure express app parse json-formatted body app.use(bodyparser.json());  //manages html fields app.use(bodyparser.urlencoded({                               extended:true                               }));   //add static path. app.use(express.static(config.root)); console.log(config.root);  //add routes users api app.get('/api/users',user.index_user); app.post('/api/users',user.create); app.put('/api/users/:id',user.update); app.delete('/api/users/:id',user.delete);  //routes player api app.get('/api/users',user.index_player);  // listen on port 8000, ip defaults 127.0.0.1 app.listen(config.port)  // put friendly message on terminal console.log("server running @ http://127.0.0."+config.port+"/"); 

my player_model.js

'use strict';  var mongoose = require('mongoose');  var schema = mongoose.schema;   var playerschema = new schema({                           player_id:number,                           name: string,                           team:{soccer:string, football:string},                           game:[{team:string, distance:string, pace:         string,heat_link:string, compare_speed:string, speed_link:string}]                           })     module.exports = mongoose.model('player', playerschema); 

any appreciated.


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -