简体   繁体   English

将nodejs app部署到heroku

[英]Deploy nodejs app to heroku

I used https://github.com/tommy351/hexo to create a blog and hope to deploy to heroku 我使用https://github.com/tommy351/hexo创建了一个博客,并希望部署到heroku

hexo instruction hexo指令

 Installation

$ npm install hexo -g

Quick Start

Setup your blog

$ hexo init blog
$ cd blog
$ npm install

Start the server

$ hexo server

Create a new post

$ hexo new "Hello Hexo"

Generate static files

$ hexo generate

I created at local and upload the app to heroku and it reported: 我在本地创建并将应用程序上传到heroku并报告:

Releasing to testApp... ....done, v3

It looks like everything is OK, just confuse how to execute command line such as 看起来一切正常,只是混淆了如何执行命令行等

hexo ***

on heroku 在heroku上

I executed 我执行了

heroku run "hexo server"

it always said 它总是说

bash: hexo: command not found

It's not the way you should deploy hexo on Heroku. 这不是你应该在Heroku上部署hexo的方式。

1. TL;DR - SHORT ANSWER 1. TL; DR - 短期答案

Hexo doc(1) says you should change your file ./_config.yml to contains something like that in this part: Hexo doc(1)表示你应该将你的文件./_config.yml更改为包含这个部分中的类似内容:

deploy:
  type: heroku
  repo: git@heroku.com:jefficue.git
  message: Deployment of Hexo to heroku.

Bug for the current version (2): You should delete public/ from the file ./gitignore. 当前版本的错误(2):您应该从文件./gitignore中删除public /。 You can check using this bash command. 您可以使用此bash命令进行检查。 It should return nothing: 它应该什么都不返回:

$ cat .gitignore|grep public
$

After you should run the following command at your project's root: 在项目的根目录下运行以下命令后:

hexo generate
hexo deploy

2. LONGER ANSWER 2.更长的答案

If you want to execute something on Heroku the command is 如果你想在Heroku上执行一些命令就是

heroku run something

In your case it seems hexo is not installed on Heroku. 在你的情况下似乎没有在Heroku上安装hexo。 Don't do it but you could add the package hexo to your dependencies: 不要这样做,但你可以将包hexo添加到你的依赖项:

{  
   "name":"hexo-site",
   "version":"2.8.3",
   "private":true,
   "dependencies":{  
      "hexo-renderer-ejs":"*",
      "hexo-renderer-stylus":"*",
      "hexo-renderer-marked":"*",
      "hexo":"*",
      "connect":"2.x"
   }
}

I've added the bold line to my./package.json and it will be automatically installed during the deployment. 我已将粗线添加到my./package.json中,它将在部署期间自动安装。 By default the package hexo is not present. 默认情况下,包hexo 存在。 This is a bad practice to add it. 添加它是一种不好的做法 You should actually: 你应该:

  1. use the hexo command locally, 在本地使用hexo命令,
  2. commit / push the result to the server. 将结果提交/推送到服务器。

(1) http://hexo.io/docs/deployment.html (1) http://hexo.io/docs/deployment.html
(2) https://github.com/hexojs/hexo/issues/764 (2) https://github.com/hexojs/hexo/issues/764

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM