2017-02-02 2 views
0

Как я могу сделать следующий код server.js для .html файлов вместо .ejs в Node JS. Благодаря!Измените .ejs на .html

var express = require('express'); 
var app = express(); 

// set the port of our application 
// process.env.PORT lets the port be set by Heroku 
var port = process.env.PORT || 8080; 

// set the view engine to ejs 
app.set('view engine', 'ejs'); 

// make express look in the public directory for assets (css/js/img) 
app.use(express.static(__dirname + '/public')); 

// set the home page route 
app.get('/', function(req, res) { 

// ejs render automatically looks in the views folder 
res.render('index'); 
}); 

app.listen(port, function() { 
console.log('Our app is running on http://localhost:' + port); 
}); 

ответ

0

Вы должны быть в состоянии просто удалите эти строки:

// set the view engine to ejs 
app.set('view engine', 'ejs'); 

// set the home page route 
app.get('/', function(req, res) { 
    // ejs render automatically looks in the views folder 
    res.render('index'); 
}); 

и добавить свои .html файлы к общественному /.

тестирования это с этим кодом

var express = require('express'); 
var app = express(); 

// set the port of our application 
// process.env.PORT lets the port be set by Heroku 
var port = process.env.PORT || 8080; 

// make express look in the public directory for assets (css/js/img) 
app.use(express.static(__dirname + '/public')); 


app.listen(port, function() { 
    console.log('Our app is running on http://localhost:' + port); 
}); 

и этой структуры каталогов

├── package.json 
├── public 
│   └── index.html 
└── server.js 

отлично работает для меня.

+0

@lessio Он говорит, что не может GET/on heroku – Lanie909

+0

Я бы предположил, что это некоторая проблема конфигурации с героку. Код, кажется, работает отлично для меня! Добавление дополнительной информации к моему ответу – leesio

Смежные вопросы