Saturday, 18 March 2017

Can't see my html file in view

I am trying to run basic mean app. My app is working without the angular part. But when I have included angular I can't see the html page which is in the "view" folder.

This is my server:

var express=require('express');
var path=require('path');
var bodyParser=require('body-parser');

var index=require('./routes/index');
var tasks=require('./routes/tasks');
var port=3000;
var app=express();

/*View engine*/
app.set('views',path.join(__dirname, 'views'));
app.set('view engine','ejs');
app.engine('html',require('ejs').renderFile);

/*View static folder*/
app.use(express.static(path.join(__dirname, 'client')));

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));

app.use('/',index);
app.use('/api',tasks);
app.listen(port, function(){
    console.log('The application is running on port '+port);
});

This is my route to index under "routes" directory:

var express=require('express');
var router=express.Router();

router.get('/',function(req, res, next){
    res.render('index.html');
})
module.exports=router;

My angular code is living in client/app directory. I am typing "npm start" when I am in myapp/client directory in the terminal. I get "Can't get/" and in the terminal I see "404 GET /index.html"

Any ideas? Thanks!



via Tuvia Khusid

No comments:

Post a Comment