Created
May 11, 2014 21:27
-
-
Save nazrdogan/0420e0640875932df33c to your computer and use it in GitHub Desktop.
MongoDB express.js
This file contains 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, cons, mongoclient, app,Server; | |
express = require('express'); | |
cons = require('consolidate'); | |
MongoClient = require('mongodb').MongoClient; | |
Server=require('mongodb').Server; | |
app = express(); | |
app.engine('html',cons.swig); | |
app.set('view engine','html'); | |
app.set('views',__dirname+'/views'); | |
var mongoclient=new MongoClient(new Server('localhost',27017,{native_parse:true})); | |
var db=mongoclient.db('app'); | |
app.get('/test.json',function(req,res){ | |
res.header("Content-Type", "application/json; charset=utf-8"); | |
db.collection('haber').find({},{ _id: 0 }).toArray(function(err,doc){ | |
var sonuc=JSON.stringify(doc); | |
res.send(sonuc); | |
}); | |
}); | |
app.get('*',function(req,res){ | |
res.send('page not found',404); | |
}); | |
mongoclient.open(function(err,mongoclient) { | |
if(err) throw err | |
app.listen(8080); | |
console.log('Server is Runnig,Bitch'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment