【问题标题】:How does Sails.js work on heroku?Sails.js 如何在 heroku 上工作?
【发布时间】:2026-01-29 16:40:01
【问题描述】:

我使用 Sails.js 创建了一个简单的应用程序并将其部署到 Heroku,它运行良好。
这是我的Procfile

web: sails lift

但是在 Heroku 上(我认为)没有安装二进制 sails,那么它是如何工作的呢?

更新

我已经从package.json 中删除了mainstart 部分,以防使用npm start 命令,但应用程序仍然可以正常运行。
我还在 Procfile 中添加了--prod 选项,并且处理正确。

这里是git push 输出(没有关于 Procfile 的警告/错误)

-----> Node.js app detected

   PRO TIP: Specify a node version in package.json
   See https://devcenter.heroku.com/articles/nodejs-support

-----> Defaulting to latest stable node: 0.10.28
-----> Downloading and installing node
-----> Restoring node_modules directory from cache
-----> Pruning cached dependencies not specified in package.json
-----> Writing a custom .npmrc to circumvent npm bugs
-----> Exporting config vars to environment
-----> Installing dependencies
-----> Caching node_modules directory for future builds
-----> Cleaning up node-gyp and npm artifacts
-----> Building runtime environment
-----> Discovering process types
   Procfile declares types -> web
-----> Compressing... done, 19.3MB
-----> Launching... done, v8

heroku logs(进程以sails lift --prod 命令启动,而不是node app.js

Slug compilation started
Slug compilation finished
Deploy 35bcbd9 by ...
Release v8 created by ..
Unidling
State changed from down to starting
Starting process with command `sails lift --prod`
memory, and will not scale past a single process.
Warning: connection.session() MemoryStore is not
designed for a production environment, as it will leak
info:    Sails.js           <|
info: 
info:                       /|.\
info:    v0.9.16             |\
info:                 `--'-------' 
info:                      / || \
info:                 .-'.-==|/_--'
info:    __---___--___---___--___---___--___
info:                    ,'  |'  \
info: To see your app, visit http://localhost:3661

debug: --------------------------------------------------------
info: Server lifted in `/app`
info:  ____---___--___---___--___---___--___-__
info: 
info: To shut down Sails, press <CTRL> + C at any time.
info: 
debug: :: Sat May 17 2014 09:37:00 GMT+0000 (UTC)
debug: 
debug: Environment : production
debug: --------------------------------------------------------
debug: Port        : 3661
State changed from starting to up

【问题讨论】:

  • 是的,我看不出你要去哪里...
  • 我的猜测(这就是我没有将其标记为答案的原因)是,如果它确实没有全局安装sails,它会使用/尝试npm start,因为它存在,它运行node app.js.
  • @CWSpear,似乎并非如此 - 我已从 package.json 中删除了 start 部分,一切正常。查看更新

标签: javascript node.js heroku sails.js


【解决方案1】:

我是否理解 heroku 从 node_modules 获取二进制文件并将它们添加到路径(或类似的东西。

另一个选项是你的 Procfile 可能没有被考虑(比如它放错地方或有问题),那么它将默认为“npm start”,这可能在你的 package.json 中重定向到“node app.js"(而不是sails 二进制文件)。

在我的情况下,我没有 Profile,它工作正常,但我不知道它是默认为“npm start”还是告诉 heroku 这样做的 codeship.io(我的构建系统) (我根本没有碰任何配置)。

更新:根据 heroku 文档 (https://devcenter.heroku.com/articles/nodejs-support),

将设置以下环境变量: PATH=vendor/node/bin:bin:node_modules/.bin:$PATH

node_modules/.bin 的东西可以解决问题 :)

【讨论】:

  • 您好,请查看更新。好像npm start 没有运行。也许 Heroku 确实安装了风帆?