Node.js 我总是得到一个“答案”;TypeError:Router.use()需要一个中间件函数,但得到一个字符串;错误

Node.js 我总是得到一个“答案”;TypeError:Router.use()需要一个中间件函数,但得到一个字符串;错误,node.js,express,Node.js,Express,我不知道为什么会发生这种情况,我已经使用Node.JS几个月了,以前从未发生过这种情况。项目文件仍然是空的,我刚刚启动了这个新项目,并试图运行它,看看我是否已将所有内容设置好并正常工作 我使用了express而不是http, mongoose和body解析器,以及客户端的EJB 以下是我的全部主要js代码: //All the requirements we will be using const express = require('express'); const mongoose = re

我不知道为什么会发生这种情况,我已经使用Node.JS几个月了,以前从未发生过这种情况。项目文件仍然是空的,我刚刚启动了这个新项目,并试图运行它,看看我是否已将所有内容设置好并正常工作

我使用了express而不是http, mongoose和body解析器,以及客户端的EJB

以下是我的全部主要js代码:

//All the requirements we will be using
const express = require('express');
const mongoose = require('mongoose');
const bodyParser = require('body-parser');

const app = express();

const dbURI = "URI";

//Connects to the DB
mongoose.connect(dbURI, {useNewUrlParser: true, useUnifiedTopology: true}, (err)=> {
    if(err) {
        console.log(err);
    } else {
        console.log('Connected to the database!');
    }
})

//Sets the settings for the website
app.use('view engine', 'ejs');

app.use(express.static('css'));
app.use(express.static('scripts'))

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

//Starts the server
app.listen(3000, 'localhost', (req, res)=> {
    if(err) {
        console.log(err)
    } else {
        console.log('Listening @ port 3000... ');
    }
})

//All the web routes
app.get('/', (req, res)=> {
    res.render('index', {title: 'Home'})
})
如果有人能帮助我理解为什么我总是犯这个错误,我将不胜感激。
提前谢谢

试试这个,而不是
应用。使用('view engine','ejs')

视图引擎实际上不是一个中间件,而是应用程序的一个配置参数

app.set('view engine', 'ejs');