node.js - 从 Heroku 上的 NodeBeginner 书中的 server.js 示例运行

标签 node.js heroku

我是 Node.js 和 Heroku 的新手。我尝试运行 Heroku 上的 nodebeginner 书中的第一个示例 server.js。 server.js 的代码是

var http = require("http");
http.createServer(function(request, response) {
    response.writeHead(200, {"Content-Type": "text/plain"});
    response.write("Hello World");
    response.end();
}).listen(8888);

为了在 Heroku 上部署 server.js,我修改了上提供的文件 https://devcenter.heroku.com/articles/nodejs

特别是,我已将文件 package.json 更改为

{
    {
        "name": "node-example",
        "version": "0.0.1",
        "dependencies": {
        "http": "0.10.x"      <=== changed this line 
    },
        "engines": {
        "node": "0.10.x",
        "npm": "1.2.x"
    }
}

但是,当我运行 npm install 时出现错误消息

npm WARN package.json node-example@0.0.1 No repository field.
npm WARN package.json node-example@0.0.1 No readme data.
npm http GET https://registry.npmjs.org/http
npm http 404 https://registry.npmjs.org/http
npm ERR! 404 'http' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it
npm ERR! 404
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, or http url, or git url.
npm ERR! System Linux 3.2.0-40-virtual
npm ERR! command "/usr/bin/node" "/usr/bin/npm" "install"
npm ERR! cwd /home/ubuntu/nodebeginner
npm ERR! node -v v0.10.12
npm ERR! npm -v 1.2.32
npm ERR! code E404

那么,我应该如何安装包“http”http://nodejs.org/api/http.html#http_http 所以我可以在 Heroku 上使用它吗?非常感谢!

最佳答案

您无需将 http 依赖项添加到 package.json 文件中——它已经是 Node 的一部分。

关于node.js - 从 Heroku 上的 NodeBeginner 书中的 server.js 示例运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17621078/

相关文章:

javascript - Node.js 和 Express - 最简单的缓存方法

node.js - 流背压如何处理多个流监听器?

javascript - 如何优化循环以插入数据库?

git - 如何在开发 Git 存储库中保留 Heroku 的部署存储库并将它们分开?

python - 在 Heroku dyno 上运行多个进程是否可行?

python - Django - 'module' 对象不可调用

node.js - 安装新版本后卡在旧版本上

node.js - 有条件地在 Express 应用程序中发送响应

mongodb - 生产中的MongoDB中的白名单IP地址

java - Spring,Prime Faces 应用程序在部署到 Heroku 时不显示 CSS