Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/430.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 获取无法在Express中发布/出错_Javascript_Node.js_Express_Kue - Fatal编程技术网

Javascript 获取无法在Express中发布/出错

Javascript 获取无法在Express中发布/出错,javascript,node.js,express,kue,Javascript,Node.js,Express,Kue,我有一个RESTful API,我正在使用postman调用我的路线/网站。每当我打电话时,邮递员都会说“不能发布/访问网站”。我正在尝试实现一个作业队列,我正在使用Express、Kue(Redis)和MongoDB 这是我的路由文件: 'use strict'; module.exports = function(app) { // Create a new website const websites = require('./controllers/website.controller.

我有一个RESTful API,我正在使用postman调用我的路线/网站。每当我打电话时,邮递员都会说“不能发布/访问网站”。我正在尝试实现一个作业队列,我正在使用Express、Kue(Redis)和MongoDB

这是我的路由文件:

'use strict';
module.exports = function(app) {
// Create a new website
const websites = require('./controllers/website.controller.js');
app.post('/websites', function(req, res) {
  const content = req.body;
  websites.create(content, (err) => {
    if (err) {
      return res.json({
        error: err,
        success: false,
        message: 'Could not create content',
      });
    } else {
      return res.json({
        error: null,
        success: true,
        message: 'Created a website!', content
      });
    }
  })
});
}
以下是服务器文件:

const express = require('express');
const bodyParser = require('body-parser');
const kue = require('kue');
const websites = require('./app/routes/website.routes.js')
kue.app.listen(3000);

var app = express();

const redis = require('redis');
const client = redis.createClient();
client.on('connect', () =>{
  console.log('Redis connection established');
})

app.use('/websites', websites);
我从未使用过Express,也不知道这里发生了什么。任何数量的帮助都将是伟大的!!
谢谢大家!

问题在于你如何使用app.use和app.post。你有

app.use('/websites', websites);
在您的网站中:

app.post('/websites', function....
因此,要获得该代码,您需要在
localhost:3000/websites/websites
上发表文章。您需要做的只是从您的路线中删除
/websites

//to reach here post to localhost:3000/websites
app.post('/' , function(req, res) {

});

你能把邮递员发来的完整错误信息贴在这里吗?谢谢!只是“无法发布/网站”这意味着
app.POST('/websites')
api处理程序未注册,express无法找到它。你也可以发布app.js文件的代码吗?我把它添加到问题中了!我没有使用app.js,所以里面没有任何内容,但我认为您正在查找此文件!它应该是
app.listen(3000)
在express中的特定端口上运行服务器。然后在你的路线上,它应该是
app.post('/api')以便您可以像http://:3000/websites/api那样调用它