我该如何解决他的“无法发布” /错误nodejs

时间:2019-06-25 07:46:37

标签: node.js

我正在尝试创建一个简单的注册页面,当我按提交时,我会收到“无法发布/ controllers / register-controller”

app / index.js中的索引

var express=require('express');
var parser=require("body-parser");
var connection=require("./config");
var registerController=require("./controllers/register-controller");
var app=express();
app.use(parser.json());
app.use(parser.urlencoded({ extended: true }));


app.get('/',function(req,res){
  res.sendFile(__dirname+"/"+"index.html");
})

app.post('/api/register',registerController.register);
app.post('./controllers/register- 
controller',registerController.register);

app.listen(5000);

app / controller / register-controller.js中的register-controller

var express=require("express");
var connection=require("./../config");
module.exports.register=function(req,res){ 
  var date=new Date();
  var users={
    "first_name": req.body.first_name,
    "last_name": req.body.last_name,
    "email": req.body.email,
    "password": req.body.password,
    "created_at": date,
    "updated_at": date
};
connection.query('insert into users set ?'
,users,function(errors,results,fields){
  if(error){
     res.json({
      status: false,
      message: "Query Error"
    })
  }
  else{
    res.json({
      status: true,
      data: results,
      message: "Registeration success"
    })
  }
 });
}

index.html在app / index.html

form action="./controllers/register-controller" method="POST">
  First Name: input type="text" name="first_name"<br/>
  Last Name:  input type="text" name="last_name"<br/>
  Email:      input type="text" name="email"><br/>
  Password:   input type="password" name="password"></br>

  input type="submit" value="Submit"
/form

我对此并不陌生,我不知道该更改什么。预先感谢!

0 个答案:

没有答案