如何将 Node.js 制作的网站发布到 Github Pages?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15718649/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 14:03:47  来源:igfitidea点击:

How to publish a website made by Node.js to Github Pages?

node.jsgithub-pages

提问by dyzdyz010

I made a website using Node.js as the server. As I know, the node.js file should start working by typing commands in terminal, so I'm not sure if Github Pages supports node.js-hosting. So what should I do?

我使用 Node.js 作为服务器创建了一个网站。据我所知,node.js 文件应该通过在终端中输入命令开始工作,所以我不确定 Github Pages 是否支持 node.js-hosting。所以我该怎么做?

采纳答案by Akshat Jiwan Sharma

GitHub pages host only static HTML pages. No server side technology is supported, so Node.js applications won't run on GitHub pages. There are lots of hosting providers, as listed on the Node.js wiki.

GitHub 页面仅托管静态 HTML 页面。不支持服务器端技术,因此 Node.js 应用程序不会在 GitHub 页面上运行。Node.js wiki上列出了许多托管服务提供商。

App fog seems to be the most economical as it provides free hosting for projects with 2GB of RAM (which is pretty good if you ask me).
As stated here, AppFog removed their free plan for new users.

应用雾似乎是最经济的,因为它为具有 2GB RAM 的项目提供免费托管(如果你问我,这非常好)。
如此处所述,AppFog 取消了他们为新用户提供的免费计划。

If you want to host static pages on GitHub, then read this guide. If you plan on using Jekyll, then this guidewill be very helpful.

如果您想在 GitHub 上托管静态页面,请阅读本指南。如果您打算使用Jekyll,那么本指南将非常有帮助。

回答by Johann Echavarria

We, the Javascript lovers, don't have to use Ruby (Jekyll or Octopress) to generate static pages in Github pages, we can use Node.js and Harp, for example:

我们 Javascript 爱好者不必使用 Ruby(Jekyll 或 Octopress)在 Github 页面中生成静态页面,我们可以使用 Node.js 和Harp,例如:

These are the steps. Abstract:

这些是步骤。抽象的:

  1. Create a New Repository
  2. Clone the Repository

    git clone https://github.com/your-github-user-name/your-github-user-name.github.io.git
    
  3. Initialize a Harp app (locally):

    harp init _harp
    
  1. 创建一个新的存储库
  2. 克隆存储库

    git clone https://github.com/your-github-user-name/your-github-user-name.github.io.git
    
  3. 初始化 Harp 应用程序(本地):

    harp init _harp
    

make sure to name the folder with an underscore at the beginning; when you deploy to GitHub Pages, you don't want your source files to be served.

确保以下划线开头的文件夹命名;当您部署到 GitHub Pages 时,您不希望提供源文件。

  1. Compile your Harp app

    harp compile _harp ./
    
  2. Deploy to Gihub

    git add -A
    git commit -a -m "First Harp + Pages commit"
    git push origin master
    
  1. 编译你的 Harp 应用

    harp compile _harp ./
    
  2. 部署到 Gihub

    git add -A
    git commit -a -m "First Harp + Pages commit"
    git push origin master
    

And this is a cool tutorialwith details about nice stuff like layouts, partials, Jade and Less.

这是一个很酷的教程约不错的东西一样的布局,泛音,玉石和较少的细节。

回答by Ram

It's very simple steps to push your node js application from local to GitHub.

将 node js 应用程序从本地推送到 GitHub 的步骤非常简单。

Steps:

脚步:

  1. First create a new repository on GitHub
  2. Open Git CMD installed to your system (Install GitHub Desktop)
  3. Clone the repository to your system with the command: git clone repo-url
  4. Now copy all your application files to this cloned library if it's not there
  5. Get everything ready to commit: git add -A
  6. Commit the tracked changes and prepares them to be pushed to a remote repository: git commit -a -m "First Commit"
  7. Push the changes in your local repository to GitHub: git push origin master
  1. 首先在 GitHub 上新建一个仓库
  2. 打开安装到系统的 Git CMD(安装GitHub Desktop
  3. 使用以下命令将存储库克隆到您的系统: git clone repo-url
  4. 如果它不存在,现在将所有应用程序文件复制到此克隆库
  5. 准备好提交: git add -A
  6. 提交跟踪的更改并准备将它们推送到远程存储库: git commit -a -m "First Commit"
  7. 将本地存储库中的更改推送到 GitHub: git push origin master