NodeJS API 与其他语言的外部部门

NodeJS API with external deps in other language

我正在开发NodeJS API,一切正常。

对于一个特定问题,我正在使用本地 CLI 依赖项来处理一些 input 文件和 output 其他内容,以防 return 来自 API.

我想知道(也许打开我的想法)我可以使用什么样的服务来为这个 API 在生产中提供服务。

想法是有一个 Node 环境(就像在我的本地),可以在同一台机器上安装外部依赖项,不一定要写在 Node.

我的具体依赖是fontforge和其他小东西。

提前致谢。

如果你需要安装用 npm 不容易安装的自定义软件,那么好的 VPS 是难上加难的。我最喜欢的 VPS 提供商是 Digital Ocean。使用 this link so you can see if it's ok for you before you pay anything. By second favorite VPS provider is Vultr because you can install custom ISOs on their servers. You can try it for free with this link,您可以免费使用两个月的基本服务器。但这将意味着您自己照顾服务器。有了像 Heroku 这样的服务,所有这些都会为你处理——但你不能在那里安装任何你想要的东西。使用 VPS 您将获得具有根访问权限的自己的服务器。通常它是 Linux 但 Digital Ocean 也支持 FreeBSD 并且有些人安装 OpenBSD,尽管它不受官方支持。使用 VPS 你可以安装任何你想要的,但你必须自己安装。总有取舍。

更多信息

正在安装节点

要在 VPS 上安装 Node,我的建议是在 /opt 中安装带有版本化目录和符号链接的程序 - 这是我为 编写的示例程序:

# change dir to your home:
cd ~
# download the source:
curl -O https://nodejs.org/dist/v6.1.0/node-v6.1.0.tar.gz
# extract the archive:
tar xzvf node-v6.1.0.tar.gz
# go into the extracted dir:
cd node-v6.1.0
# configure for installation:
./configure --prefix=/opt/node-v6.1.0
# build and test:
make && make test
# install:
sudo make install
# make a symlink to that version:
sudo ln -svf /opt/node-v6.1.0 /opt/node

有关详细信息,请参阅

您的启动脚本

要在服务器启动时很好地启动您自己的应用程序 - 这是一个基于我正在使用的脚本的示例 Upstart 脚本 - 它应该可以在 Ubuntu 14.04 上运行,未在较新版本上测试 - 保存它在 /etc/init/YOURAPP.conf:

# When to start the service
start on runlevel [2345]

# When to stop the service
stop on runlevel [06]

# If the process quits unexpectadly trigger a respawn
respawn

# Start the process
exec start-stop-daemon --start --chuid node --make-pidfile --pidfile /www/YOURAPP/run/node-upstart.pid --exec /opt/node/bin/node -- /www/YOURAPP/app/app.js >> /www/YOURAPP/log/node-upstart.log 2>&1

只需更改:

  • YOURAPP 到您自己的应用程序的名称
  • /opt/node/bin/node 通往 node
  • 的路径
  • /www/YOURAPP/app/app.js 到您的 Node 应用程序的路径
  • /www/YOURAPP/run 到您想要 PID 文件的位置
  • /www/YOURAPP/log 到您想要日志的位置
  • --chuid node--chuid OTHERUSER 如果您希望它 运行 作为与 node
  • 不同的用户

(确保添加一个名称来自上面 --chuid 的用户)

/etc/init/YOURAPP.conf 到位后,您可以安全地重新启动服务器并让您的应用程序仍在 运行ning,您可以 运行:

start YOURAPP
restart YOURAPP
stop YOURAPP

启动、重新启动和停止您的应用程序 - 这也会在系统启动或关闭期间自动发生。