Created
February 15, 2017 18:20
-
-
Save bmakarand2009/330000bd8b67b680c7668ed17516f457 to your computer and use it in GitHub Desktop.
herokuconfig vrs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require("express"); | |
var bodyParser = require('body-parser').json(); | |
var app = express(); | |
var MongoClient = require('mongodb').MongoClient; | |
var assert = require('assert'); | |
var ObjectId = require('mongodb').ObjectID; | |
var cron = require('node-cron'); | |
var cronTask = require('./modules/cronConfig/cron') | |
if(!process.env.MLABURI) var config = require('./config/mongo'); | |
var mongoUrl = process.env.MLABURI || config.mongoURI; | |
app.listen(process.env.PORT || 3000); | |
console.log("Server running on port 3000"); | |
//cron.schedule('* * * * *', function() { | |
cronTask(); | |
//}); | |
app.post('/meal', bodyParser, function(req, res) { | |
var insertDocument = function(db, callback) { | |
db.collection('meal').insertOne(req.body, function(err, result) { | |
if(err) res.status(500).json(err); | |
else res.status(200).json(result); | |
assert.equal(err, null); | |
console.log("Inserted a document into the meal collection."); | |
callback(); | |
}); | |
}; | |
MongoClient.connect(mongoUrl, function(err, db) { | |
assert.equal(null, err); | |
insertDocument(db, function() { | |
db.close(); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment