具有其他语言的外部部门的NodeJS API [英] NodeJS API with external deps in other language

查看:103
本文介绍了具有其他语言的外部部门的NodeJS API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am developing a NodeJS API and everything is ok.

对于特定问题,我正在使用本地CLI依赖项,该依赖项会处理一些 input 文件和 output 其他内容,以防从API返回.

For an specific issue I am using a local CLI dependency that process some input files and output other stuff, in case to return from the API.

我想知道(也许让我敞开心mind)我可以在生产中为该API提供什么样的服务.

I wanted to know (maybe open my mind on) what kind of service I can use to serve this API in production.

这个想法是要有一个Node环境(例如在我的本地环境中),该环境可以在同一台计算机上安装不一定要用Node编写的外部依赖项.

The idea is to have a Node environment (like in my local) that can have installed in the same machine an external dependency not necessarily written in Node.

我的特定依赖项是 fontforge 和其他小东西.

My specific dependency is fontforge and other little things.

谢谢.

推荐答案

如果您需要安装不易通过npm安装的自定义软件,那么很难击败一个好的VPS.我最喜欢的VPS提供商是Digital Ocean.使用此链接,您可以免费使用两个月的基本服务器.没关系,先付款.第二受欢迎的VPS提供商是Vultr,因为您可以在其服务器上安装自定义ISO.您可以通过此链接免费试用.但这将意味着您要自己照顾服务器.借助Heroku之类的服务,一切都会为您服务-但您无法在此处安装任何内容.使用VPS,您将获得具有root用户访问权限的服务器.通常它是Linux,但是Digital Ocean也支持FreeBSD,并且某些人安装了OpenBSD,尽管它并未得到官方支持.使用VPS,您可以安装任何所需的东西,但您必须自己做.总会有一个权衡.

It's hard to beat a good VPS if you need to install custom software that is not easy to install with npm. My favorite VPS provider is Digital Ocean. You can have two months of a basic server for free with 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. But it will mean taking care of the server yourself. With services like Heroku all of that is taken care for you - but you can't install whatever you want there. With a VPS you get your own server with root access. Usually it's Linux but Digital Ocean also supports FreeBSD and some people install OpenBSD, though it's not officially supported. With a VPS you can install whatever you want, but you have to do it yourself. There is always a trade off.

要在VPS上安装Node,我的建议是在具有版本目录和符号链接的/opt中安装-这是我为

To install Node on the VPS, my recommendation is to install in /opt with a versioned directory and a symlink - this is an example procedure that I wrote for a different answer:

# 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

请参见

See this answer for more info.

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

To have your own application nicely started on server startup - here is an example Upstart script based on the one that I'm using - it should work on Ubuntu 14.04, not tested on newer versions - save it in /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/nodenode
  • 的路径
  • /www/YOURAPP/app/app.js到您的Node应用程序的路径
  • /www/YOURAPP/run到您想要PID文件的位置
  • /www/YOURAPP/log到您想要记录日志的位置
  • --chuid node--chuid OTHERUSER,如果您希望它以不同于node
  • 的用户身份运行
  • YOURAPP to the name of your own app
  • /opt/node/bin/node to your path to node
  • /www/YOURAPP/app/app.js to the path of your Node app
  • /www/YOURAPP/run to where you want your PID file
  • /www/YOURAPP/log to where you want your logs
  • --chuid node to --chuid OTHERUSER if you want it to run as a different user than node

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

(make sure to add a user with a name from --chuid above)

安装好/etc/init/YOURAPP.conf后,您可以安全地重新启动服务器并使应用程序仍在运行,您可以运行:

With your /etc/init/YOURAPP.conf in place you can safely restart your server and have your app still running, you can run:

start YOURAPP
restart YOURAPP
stop YOURAPP

启动,重新启动和停止您的应用-在系统启动或关闭过程中也会自动发生.

to start, restart and stop your app - which would also happen automatically during the system boot or shutdown.

这篇关于具有其他语言的外部部门的NodeJS API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆