So it's time for my node.js/express application to go live. It works fine at my local development environment. I'm new to both node.js and mongoDB. I decided to us nodejitsu as hoster.
The first thing i need to do is to create the database at nodejitsu. Then i must configure my code so it connects to the created database. How should this be configured? In my local development environment the objects have just been stored like a seed and not actually a database.
I'm feeling i missing some major parts here on how to get my application up and running. Would realy appreciate if someone could help me sort out it a bit.
Heres the code that works localy:
var mongo = require('mongodb');
var Server = mongo.Server,
Db = mongo.Db,
BSON = mongo.BSONPure;
var server = new Server('localhost', 27017, {auto_reconnect: true});
db = new Db('spotdb', server);
db.open(function(err, db) {
if(!err) {
console.log("failed to connect to 'spotdb' database");
db.collection('spots', {strict:true}, function(err, collection) {
if (err) {
console.log("The 'spots' collection dont exist. Creating it with dbseed");
dbSeed();
}
});
}
});
var dbSeed = function() {
var spots = [
{
name: "A name",
description: "Description",
picture: "picture.jpg"
},
{
name: "Number two",
description: "Descp",
picture: "image.jpg"
}];
db.collection('spots', function(err, collection) {
collection.insert(spots, {safe:true}, function(err, result) {});
});
};