我是 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/