my mongo database not connect with my node server. here my code.
Expand|Select|Wrap|Line Numbers
- .................controller.js...............
- function AppCtrl($scope,$http){
- console.log('hello 123456789')
- $http.get('/contactlist').success(function(response){
- console.log('i requested')
- $scope.contactlist = response;
- });
- $scope.addContact = function(){
- console.log($scope.contact)
- $http.post('/contactlist', $scope.contact);
- };
- };
- .....................server.js................
- var express = require('express');
- var app = express();
- var mongojs = require('mongojs');
- var db = mongojs('contactlist', ['contactlist']);
- var bodyParser = require('body-parser');
- /*app.get('/', function(req,res){
- res.send('hello world from server.js')
- });*/
- app.use(bodyParser.json());
- app.use(express.static(__dirname + '/public'));
- app.use('/contactlist',function(req,res){
- console.log('server saying: i received a get request')
- db.contactlist.find(function(err,docs){
- console.log(docs);
- res.json(docs);
- })
- });
- app.post('/contactlist', function(req, res){
- console.log(req.body);
- })
- app.listen(3000);
- console.log('server:i am running');