node.js - [Error: failed to connect to [localhost:27017]] . This error is occuring On mongodb -


this question has answer here:

my sample code here. learning book developing_backbone.js_applications have installed mongodb on pc. searched on site answers no clue. has got solutions? thanks!

// module dependencies. var application_root = __dirname,     express = require('express'), //web framework     path = require('path'), //utilities dealing file paths     mongoose = require('mongoose'); //mongodb integration //create server var app = express(); // configure server app.configure(function () {     //parses request body , populates request.body     app.use(express.bodyparser());     //checks request.body http method overrides     app.use(express.methodoverride());     //perform route lookup based on url , http method     app.use(app.router);     //where serve static content     app.use(express.static(path.join(application_root, 'site')));     //show errors in development     app.use(express.errorhandler({         dumpexceptions: true,         showstack: true     })); });   //start server var port =4711; app.listen(port, function () {     console.log('express server listening on port %d in %s mode',         port, app.settings.env); });  // routes app.get( '/api', function( request, response ) {      response.send( 'library api running , requestis' ); });  //connect database mongoose.connect( 'mongodb://localhost/library_database', function(err) { if (err) console.log(err); } ); //schemas var book = new mongoose.schema({     title: string,     author: string,     releasedate: date }); //models var bookmodel = mongoose.model( 'book', book );  //get list of books app.get( '/api/books', function( request, response ) {     return bookmodel.find( function( err, books ) {         if( !err ) {             return response.send( books );         } else {             return console.log( err );         }     }); }); 

do have mongodb installed , running locally?? leave terminal tab or window open mongo running there.


Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -