JavaScript Node.js/MongoDB: How can I use module.exports to pass a localhost database url to server.js file? node js mongodb,node js mongodb tutorial,node js mongodb

I have a problem with connection to a database with mongoose on localhost.

In my server.js file I have:

var express     = require('express');
var app         = express();                        //Create our app with express
var mongoose    = require('mongoose');              //Mongoose for mongoDB
var database    = require('./config/database.js');  //Load the database config

...

//Configuration =====================
mongoose.connect('database.url');   //Connect to mongoDB database

...

In my database.js file I have:

// Config/database.js

module.exports = {
url : 'mongodb://127.0.0.1:27017/test'
};

The error I get in my node.js command prompt is:

events.js:141
  throw er; // Unhandled 'error' event
  ^

Error: failed to connect to [database.url:27017]
at null.<anonymous> (C:\*filepath*\node_modules\mongoose\node_modules\mongodb\lib\mongodb\connection\server.js:540:25)
at emitThree (events.js:97:13)
at emit (events.js:175:7)
at null.<anonymous> (C:\*filepath*\node_modules\mongoose\node_modules\mongodb\lib\mongodb\connection\connection_pool.js:140:15)
at emitTwo (events.js:87:13)
at emit (events.js:172:7)
at Socket.<anonymous> (C:\*filepath*\node_modules\mongoose\node_modules\mongodb\lib\mongodb\connection\connection.js:478:10)
at emitOne (events.js:77:13)
at Socket.emit (events.js:169:7)
at emitErrorNT (net.js:1256:8)

When I use mongodb://127.0.0.1:27017/test in place of database.url it works just fine.

I'm currently using node.js v4.2.6 and mongodb 3.2 on Windows 10.

How can I get module.exports to pass the url to the server.js?

Answer:1

Remove '', because now you are trying connect to mongodb with url 'database.url', but you need use url property from database that contains right url mongodb://127.0.0.1:27017/test

mongoose.connect(database.url); 
Answer:2

This is my Html5 code.. Problem is that "Text is not fully read by the voice. It stops in half way."What I need to do for that? Am using the script inside the html <!DOCTYPE html> <html ...

This is my Html5 code.. Problem is that "Text is not fully read by the voice. It stops in half way."What I need to do for that? Am using the script inside the html <!DOCTYPE html> <html ...

  1. html5 javascript text to speech
  2. html5 javascript text
  3. html5 javascript copy text to clipboard
  4. html5 javascript input text
  5. html5 javascript write text file
  6. html5 javascript create text file
  7. html5 javascript change button text
  8. html5 script typeu003d text/javascript srcu003d
  9. javascript html5 canvas draw text
  10. html5 typeu003d text/javascript
  11. html5 script typeu003d text/javascript
  12. html5 javascript draw text
  13. html5 typeu003d text/javascript 不要

I have a template in which photos are being displayed in a frame ( each frame is different for different images) .I have written a function which uses the images original height and width and gives me ...

I have a template in which photos are being displayed in a frame ( each frame is different for different images) .I have written a function which uses the images original height and width and gives me ...

what i need is, When i click on button "Click", the Column "Delete" Should be visible and editable. and when i click on the same button "click" again, the delete column should slide right and hide ...

what i need is, When i click on button "Click", the Column "Delete" Should be visible and editable. and when i click on the same button "click" again, the delete column should slide right and hide ...

  1. show hide div sliding effect

What is this code doing? How is it executing? What is x equal to? Another useful type of higher-order function modifies the function value it is given: function negate(func) { return function(x) { ...

What is this code doing? How is it executing? What is x equal to? Another useful type of higher-order function modifies the function value it is given: function negate(func) { return function(x) { ...

  1. does this function have an inverse
  2. does this function converge
  3. does this function have an inverse calculator
  4. does this function have a maximum or a minimum
  5. does this function converge or diverge
  6. what does this function mean
  7. does function of beauty work
  8. does function of beauty actually work
  9. does function of beauty really work
  10. does function of beauty contain silicones
  11. does function of beauty have silicones
  12. does function
  13. does function have vertical asymptote
  14. does function mean in math