最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Router.use()需要一个中间件的功能,但在我的节点文件中得到了一个对象

运维笔记admin6浏览0评论

Router.use()需要一个中间件的功能,但在我的节点文件中得到了一个对象

Router.use()需要一个中间件的功能,但在我的节点文件中得到了一个对象

新来的节点,请解决错误Router.use()需要一个中间件的功能,但有一个对象

const bodyParser = require('body-parser');
const express = require('express');
const app = express();

var productRoutes = require('./api/routes/product');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}))

app.use('/products', productRoutes);

module.exports = app;

api/routes/product.js

const express = require('express');
const router = express.Router();
router.get('/', (req, res, next) => { 
  res.status(200).json({message: "Here we are handling the get request for the products"});
});
回答如下:

你改变qazxsw POI代码。将正常工作。

api/routes/product

原因是你没有导出你的路由器到其他文件时,你写在文件const express = require('express'); const router = express.Router(); router.get('/', (req, res, next) => { res.status(200).json({ message: "Here we are handling the get request for the products" }); }); module.exports = router; 则将导出。

发布评论

评论列表(0)

  1. 暂无评论