Connect Nodejs Mongodb and Angular with https

nodejs file

var fs = require('fs');
var https = require('https');
var privateKey = fs.readFileSync('certs/www.beetalkweb.com.key', 'utf8');
var certificate = fs.readFileSync('certs/bba86444d2e3bca1.crt', 'utf8');

var credentials = {key: privateKey, cert: certificate};
var express = require('express');
var app = express();

var MongoClient = require('mongodb').MongoClient;
var url = "mongodb://Fespunaa:1982Fesp1982@127.0.0.1:27017/";

var bodyParser = require('body-parser')

app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});

app.get('/', function(req, res, next) {
// Handle the get for this route
res.render('index', {});

});

app.post('/', function(req, res, next) {
// Handle the post for this route
});

app.get('/conne', function (req, res) {

MongoClient.connect(url, function(err, db) {
if (err) throw err;
var dbo = db.db("myads");

dbo.collection("ads").find({"ad_name":"adname"}).toArray(function(err, result) {

if (err) throw err;

res.send(result);

db.close();
});
});

})

app.post('/conne', function (req, res) {

MongoClient.connect(url, function(err, db) {
if (err) throw err;
var dbo = db.db("myads");

dbo.collection("ads").find({"ad_name":"adname"}).toArray(function(err, result) {

if (err) throw err;

res.send(result);

db.close();
});
});

})

var httpsServer = https.createServer(credentials, app);
httpsServer.listen(8443);

Angular / html file


WeTalk



{{content}}


ver en editar texto innterior