mongoose node.js服务器没有响应,也没有运行

ohfgkhjo  于 2023-06-23  发布在  Go
关注(0)|答案(1)|浏览(90)

我对node很陌生,我试图为iOS notes应用程序创建一个简单的服务器,但当我在命令提示符下输入node server.js时,什么也没有发生。

//CREATE A NOTE
//Post request
app.post("/create", (req, res) => {

    var Note = new Data({

        note: req.get("note"),
        title: req.get("title"),
        date: req.get("data"),
    })

    note.save().then(() => {
        if (note.isNew == false){
            console.log("Save data!")
            res.send("Saved data")
        }else {
            console.log("Failed to save data")
        }
    })
})

// http://10.11.210.1:8081/create
var server = app.listen(8081, "10.11.210.1", function(){
    console.log("Server is running!")
})

enter image description here

vof42yt1

vof42yt11#

/ import express (after npm install express)
const express = require('express');

// create new express app and save it as "app"
const app = express();

// server configuration
const PORT = 8080;

// create a route for the app
app.get('/', (req, res) => {
  res.send('Hello World');
});

//Post request
app.post("/create", (req, res) => {

  var Note = new Data({

    note: req.get("note"),
    title: req.get("title"),
    date: req.get("data"),
  })

  note.save().then(() => {
    if (note.isNew == false) {
      console.log("Save data!")
      res.send("Saved data")
    } else {
      console.log("Failed to save data")
    }
  })
})

// make the server listen to requests
app.listen(PORT, () => {
  console.log(`Server running at: http://localhost:${PORT}/`);
});

相关问题