Error: No default engine was specified and no extension was provided

前端 未结 14 2601
别跟我提以往
别跟我提以往 2020-11-29 18:13

I am working through setting up a http server using node.js and engine. However, I keep running into issues that I have little information on how to resolve I would apprecia

14条回答
  •  我在风中等你
    2020-11-29 18:37

    I just got this error message, and the problem was that I was not setting up my middleware properly.

    I am building a blog in the MEAN stack and needed body parsing for the .jade files that I was using on the front end side. Here is the snippet of code from my "/middleware/index.js" file, from my project.

    var express = require('express');
    var morgan = require('morgan');
    var session = require('express-session');
    var cookieParser = require('cookie-parser');
    var bodyParser = require('body-parser');
    
    module.exports = function (app) {
    app.use(morgan('dev'));
    
    // Good for now
    // In the future, use connect-mongo or similar
    // for persistant sessions
    app.use(bodyParser.json());
    app.use(bodyParser.urlencoded({
        extended: true
    }));
    app.use(cookieParser());
    app.use(session({secret: 'building a blog', saveUninitialized: true, resave: true}));
    

    Also, here is my "package.json" file, you may be using different versions of technologies. Note: because I am not sure of the dependencies between them, I am including the whole file here:

    "dependencies": {
        "body-parser": "1.12.3",
        "consolidate": "0.12.1",
        "cookie-parser": "1.3.4",
        "crypto": "0.0.3",
        "debug": "2.1.1",
        "express": "4.12.2",
        "express-mongoose": "0.1.0",
        "express-session": "1.11.1",
        "jade": "1.9.2",
        "method-override": "2.3.2",
        "mongodb": "2.0.28",
        "mongoose": "4.0.2",
        "morgan": "1.5.1",
        "request": "2.55.0",
        "serve-favicon": "2.2.0",
        "swig": "1.4.2"
      }
    

    Hope this helps someone! All the best!

提交回复
热议问题