node server.js什么都不返回

时间:2016-09-24 21:27:57

标签: node.js terminal nodes node-modules

我对Node非常陌生。我刚刚通过Brew安装它,当我在终端中运行keep_going = "y" while keep_going == "y": sales = float(input("Enter the amount of sales: ")) comm_rate = 10 commission = sales * comm_rate print ("The commission is: "),commission keep_going = input("Do you want to calculate another commission? (Enter y for yes): ") main()时,终端几个小时都没有做任何事情。

node server.js

这是服务器文件,它来自我正在观看的教程视频。这个简单的快速服务器的目的是让我能够通过HTTP快速地将测试数据提供给前端。

package.json:

 node -v
 v6.6.0

server.js文件:

{
    "name": "simple-server",
    "version": "1.0.0",
    "description": "",
    "main": "server.js",
    "scripts": {
         "test": "echo \"Error: no test specified\" && exit 1",
        "start": "node server.js"
    },
    "author": "",
    "license": "ISC",
    "dependencies": {
        "body-parser": "^1.14.1",
        "express": "^4.13.3",
        "path": "^0.12.7"
    }
}

提前致谢

1 个答案:

答案 0 :(得分:2)

尝试在console.log("started!")之前添加app.listen。我猜测服务器启动了,但正如你的代码所示,它唯一的日志就是收到请求时。

尝试在浏览器中访问http://localhost:6069/persons

编辑:这定义了服务器响应

app.get('/persons', function(req, res) { 
   console.log("GET From SERVER");
   res.send(persons); <-- server sends persons array to client
});