- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有带有 nodejs 的后端服务器并部署在 heroku 上。
问题是我需要使用一些基于 fortran 的程序和 dll 文件(64 位和 32 位都存在,并使用 64 位)。
为了处理所有这些问题,我编写了一些 C++ 代码 (node-addon-api)。
带有 node-gyp 的 C++ 构建到 .node 文件,并且它在我的本地环境中工作。
但是,它在 heroku 上失败并出现以下错误。
Error: /app/refprop/refpropNapi.node: invalid ELF header
而且我找到了一些关于 ELF header 错误的解释。经过一番搜索后,我在下面找到了答案,它似乎非常适合我的情况。
我的 node-addon-api 开发环境是 Windows 10,64 位。我的假设是 heroku 使用 Linux 操作系统,这就是编译的节点文件不起作用的原因。
最后,我有 3 个问题。
在Docker上编译C++和dll(我不知道如何在Docker中详细构建)是否会创建可以在heroku上执行的节点?
是否有必要对后端和 node-addon-api 进行 docker 化以确保它们在同一操作系统中运行?
看来使用docker部署让IaaS更容易,这让我逃避PaaS(heroku),但我没有任何经验。这会是逃离 heroku 的一种方式吗? (我不想再和服务器打交道了,因为我现在工作已经够多了……)
最佳答案
简答:
编译后的 .node 必须与其部署到的特定架构相匹配。在 docker 镜像中编译然后部署该 docker 镜像是一种方法,但它增加了复杂性,特别是围绕设置、使用和管理 docker 的额外步骤。使用 heroku 的 build
脚本为节点执行此操作的方法不那么复杂。 https://devcenter.heroku.com/changelog-items/1557和 https://devcenter.heroku.com/articles/nodejs-support#customizing-the-build-process
长答案:
这里有更多关于 Heroku 'dyno' 是什么的详细信息,它运行一个 Heroku 应用程序,作为背景。 https://stackoverflow.com/a/21463495和 https://devcenter.heroku.com/articles/how-heroku-works#building-applications
他们用于新应用程序的堆栈列在 https://devcenter.heroku.com/categories/stacks
目前是:
_________________________________________________________________
|Stack Version | Base Technology | Supported through |
|Heroku-18 (default) | Ubuntu 18.04 | April 2023 |
|Heroku-16 | Ubuntu 16.04 | April 2021 Learn more |
|Container | Docker | Developer-maintained* |
_________________________________________________________________
堆栈具有在 https://github.com/heroku/heroku-buildpack-nodejs 中描述的节点构建包构建您添加到 heroku 的节点应用程序。
您可以按照 https://devcenter.heroku.com/articles/nodejs-support#customizing-the-build-process 中的说明自定义构建过程和 https://devcenter.heroku.com/changelog-items/1557这意味着您可以添加一个构建脚本,每次将您的应用程序添加到 heroku 时该脚本都会运行。
"scripts": {
"start": "node index.js",
"build": "build steps here to compile your dll on heroku using node-gyp or npm build or npm install"
}
或者您可以使用 heroku-prebuild 或 heroku-postbuild 脚本。
"scripts": {
"heroku-prebuild": "echo This runs before Heroku installs your dependencies.",
"heroku-postbuild": "echo This runs afterwards."
}
https://nodejs.org/api/addons.html#addons_building更详细地描述了如何构建 C++ 插件。
免责声明:我不是 Heroku 员工,我最近也没有使用过 Heroku,所以我只是按照公开文档中的描述进行操作。
考虑到关于您可能想使用什么而不是 docker 的解释,以下是您列出的问题的答案:
- Would compiling C++ and dll on Docker (I don't know how to build in Docker in detail) would create node that can be executed on heroku?
是的。 Heroku 直接支持 docker 容器,或者您可以在与 Heroku 使用的内容相匹配的 docker 镜像(例如 Ubuntu 18.04)上编译并使用编译后的代码。
- Would it be NECESSARY to dockerize both backend and node-addon-api to ensure they run in same OS?
如果您使用的是 docker 容器,后端和 node-addon-api 都需要在同一个 docker 镜像中运行。如果你只在 docker 上编译,编译后的 c++ 需要匹配最终运行的操作系统节点。
- It seems that deploying using docker makes IaaS much easier, which makes me to escape PaaS (heroku), but I don't have any experience. Will it be a way to escape from heroku? (I don't want to work with server more, because I have enough work by now...)
是的。还有其他提供商提供可以运行节点服务器的 docker 容器服务。还有其他具有虚拟镜像的云提供商可以运行节点服务器而无需 dockerize。
关于c++ - 如何构建与操作系统隔离的 node-addon-api?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58707269/
我用运行 Node node --debug app OR node --debug-brk app 它有反应 debugger listening on port 5858 Express serv
这个问题在这里已经有了答案: What is the difference between (int *i) and (int* i) in context of both C and C++? [
我有一个应用程序,它通过消息队列将数据库写入命令分派(dispatch)给工作人员(数量非常大),因此无法保证它们的接收顺序。 我有两个 Node ,例如“Account”和“Media”。在此假设的
有没有办法在调用 ts-node 时将选项传递给 Node ?我正在尝试在 Node 中使用一个实验性功能,如果它能与 ts-node 一起使用,那就太好了。 这就是我目前正在做的事情: ts-nod
我有一个容器化的Node应用程序,它在DigitalOcean服务器上运行。当我更新服务器上的应用程序时,该应用程序必须关闭一小段时间。为了能够更新应用程序并避免停机,我目前正在阅读零停机时间部署/蓝
我正在编写一个 Node.js 应用程序。我正在使用 request 和 Cheerio 加载一组 URL 并获取该网站的大量信息,现在假设我想要获取的只是标题: var urls = {"url_1
如果不弹出以下错误,我无法安装任何 Node.js 模块。错误代码引用package.json文件。如果知道为什么会发生这种情况,我们将不胜感激。 最佳答案 这些不是错误,它们只是警告。一切都应该如此
如果我运行(从我的项目目录中): supervisor javascripts/index.js 我得到:/usr/bin/env: Node :没有这样的文件或目录 如果我运行: node java
我已遵循使用 Node-Inspector 的所有步骤 但是当我打开应用程序时,我在控制台上看不到任何脚本或日志。 我的应用程序在端口 4000 上运行。我认为唯一可能发生冲突的是端口 8080 上的
我在android中使用rxjava2,有时会遇到这样的问题: Observable.fromArray( // maybe a list about photo url in SD
我目前正在使用 Node 光纤来编写同步服务器端代码。我主要通过 try-catch block 进行错误处理,但外部库或其他小部分异步代码中总是有可能发生错误。我正在考虑使用新的域功能来尝试将这些错
看起来node-debug是node-inspector周围的一个shell?分别什么时候应该使用? 最佳答案 如果您安装node-debug,您只能访问node-debug命令。 如果您安装node
我目前正在代理后面工作,该代理不允许我执行此命令的 HTTP GET 请求阶段: Node node-sass/scripts/build.js 请求阶段: gyp http GET https://
听说node js可以用在服务端。我以前用过jsp。 jsp页面内部的java代码对客户端是不可见的。如果 Node js 只是 javascript,那么它如何对客户端不可见? 最佳答案 首先,No
我正在为 Node native 插件从 node-waf 构建迁移到 node-gyp 构建系统。 node-gyp 说它支持多个目标版本,但我在使用 node-gyp 时找不到如何指定目标 Nod
给定一个 $node ,我正在尝试在以下两种输出该 $node 的方式之间做出决定。 要么 $output = theme('node', $node); 或 node_build_content($
如果package.json中的窗口A打开一个新窗口B,node-main如何访问它?这是我的代码: package.json { "main": "index.html",
我试图在我的 xml 中的特定节点 ( ) 之前插入一个注释节点。这是它的方法: function test(xmlResponse) { var parser = new DOMParse
我正在尝试做npm install wrtc使用 Node 版本 16.14.0 但这还没有完成。它在给npm error code 1所以我试图将 Node 版本更改为以前的 lts 14.19.0
当我在 Visual Studio 中运行 Node.js 应用程序时,我收到以下消息:DeprecationWarning: 'node --debug' 和 'node --debug-brk'
我是一名优秀的程序员,十分优秀!