我对node.js很新。我只是按照快递js的基本教程。我面临的问题是我即使按照这些步骤后也无法呈现index.ejs文件。在命中localhost时我得到了ReferenceError:index未定义 在C:\ NodeJS \ expressDemo.js:28:13
expressDemo.js:
var express= require('express');
var bodyParser= require('body-parser');
var path= require('path');
var app = express();
/* var logger = function(req, res, next){
console.log("logging");
next();
}
app.use(logger); */ //middleware
//view engine--ejs
app.set('view engine','ejs');
app.set('views',path.join(__dirname,'views'));
/* body parser middleware */
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended:false}));
app.get('/',function(req,res){
res.render(index);
});
app.listen(3000, function(){
console.log("application started on 3000 port");
})
答案 0 :(得分:1)
app.get('/',function(req,res){
res.render("index");
});