Nodejs: Error: Cannot find module 'html'

后端 未结 3 1558
生来不讨喜
生来不讨喜 2021-02-01 22:12

im using nodejs and im trying to serve only html files (no jade, ejs ... engines).

heres my entry point (index.js) code:

var express = require(\'express         


        
3条回答
  •  臣服心动
    2021-02-01 22:29

    You need to specify your view folder and parse the engine to HTML.

    var express = require('express');
    var bodyParser = require('body-parser');
    
    var app = express();
    
    app.set('port', (process.env.PORT || 5000));
    app.use(express.static(__dirname + '/public'));
    app.set('views', __dirname + '/public/views');
    app.engine('html', require('ejs').renderFile);
    app.set('view engine', 'html');
    
    app.use(bodyParser.urlencoded({
      extended: true
    }));
    app.use(bodyParser.json());
    
    
    
    app.get('*', function(req, res){
        res.render('index.html');
    });
    
    app.listen(app.get('port'), function() {
    });
    

提交回复
热议问题