when i'm running angular, the page Connection refused problem araised
return this.http.get('http://localhost:3000/api/contacts') .map(res=>res.json());
if suppose i m running nodejs separately, its work fine... but when i running angular, this would not make connection to nodejs. It show console error message as Failed to load resource: net::ERR_CONNECTION_REFUSED Failed to load resource: net::ERR_CONNECTION_REFUSED and EXCEPTION: Response with status: 0 for URL: null
This is my app.js file
var express =require('express');
var mongoose=require('mongoose');
var bodyparser=require('body-parser');
var cors=require('cors');
var path=require('path');
var app=express();
const route=require('./routes/route');
mongoose.connect('mongodb://localhost:27017/app_store');
mongoose.connection.on('connected',()=>{
console.log('Connected to database mongodb@27017');
});
mongoose.connection.on('error',(err)=>{
if(err){console.log('Error in Database Connection'+err);
}})
const port =3000;
app.use(cors());
app.use(bodyparser.json());
app.use(express.static(path.join(__dirname,'public')));
app.use('/api',route);
app.get('/',(req,res)=>{
res.send('foobar');
});
app.listen(port,()=>{
console.log('Server started at port:'+port);
});
via Ram
No comments:
Post a Comment