我有一个在 nodejs 上运行的 javascript 程序。如果我运行以下命令:
node app.js
它继续运行,但有时会退出。但是我想在它退出时自动重新启动它。
对于 Linux 系统,是否有任何命令可以这样做?请注意,我不想使用 cron 作业。
将 node.js 目录添加到 cygwin 路径会破坏 ls 命令:
Starting /bin/bash.exe
myidt@DESKTOP-IV5C6TI /cygdrive/d/tmp/node_ls_ko
$ touch toto
user@DESKTOP /cygdrive/d/tmp/node_ls_ko
$ ls
toto
user@DESKTOP /cygdrive/d/tmp/node_ls_ko
$ PATH=/cygdrive/d/brl/app/node-v14.17.6-win-x64:%PATH%
user@DESKTOP /cygdrive/d/tmp/node_ls_ko
$ ls
bash: ls : commande introuvable
当然,节点目录不包含任何看起来像“ls”的东西:
在新的 cygwin 终端中如下所示:
$ ls /cygdrive/d/brl/app/node-v14.17.6-win-x64
asciidoctor-pdf asciidoctor-web-pdf.ps1 install_tools.bat node.exe npm
asciidoctor-pdf.cmd CHANGELOG.md jhipster node_etw_provider.man npm.cmd
asciidoctor-pdf.ps1 inliner jhipster.cmd node_modules npx
asciidoctor-web-pdf inliner.cmd jhipster.ps1 nodevars.bat npx.cmd
asciidoctor-web-pdf.cmd inliner.ps1 LICENSE nodevars_my.bat README.md
我加入来问这个问题,因为它看起来不像是堆栈溢出问题。
问题:在 nvm 上运行的 Node 和 npm 已安装并正常工作,但在出现错误时(我尝试过的)没有任何工作。我怀疑错误出在操作系统级别(权限或文件问题),但我不确定如何解决这些问题。您能否告诉我出了什么问题(如果下面有足够的信息)或在哪里寻找解决方案(如果下面的信息不够或不正确)。
我在 Manjaro 上已经有一段时间了,我仍然是 Linux 的初学者。我一直在使用 NVM 来管理多个 node.js 版本,而不久前它停止了工作。我有时只使用我的电脑,我认为这是一些节点问题,但今天我进去完全删除了 nvm/node,然后重新安装了它们。然后我尝试启动一个标准的 NUXT 应用程序,但它失败了,所以我认为它是在操作系统级别。
我安装了 NVM,然后安装了 LTS 节点(12.14),然后我尝试了一个新的 nuxt 项目:
npx create-nuxt-app test
回答所有问题,开始灌输......很多错误 - 但它结束了......错误示例:
../lib/kerberos.cc: In static member function ‘static Nan::NAN_METHOD_RETURN_TYPE Kerberos::AuthGSSServerStep(Nan::NAN_METHOD_ARGS_TYPE)’:
../lib/kerberos.cc:802:44: error: no matching function for call to ‘v8::Value::ToObject()’
802 | Local<Object> object = info[0]->ToObject();
| ^
In file included from /home/un/.cache/node-gyp/12.14.0/include/node/node.h:63,
from ../lib/kerberos.h:4,
from ../lib/kerberos.cc:1:
/home/un/.cache/node-gyp/12.14.0/include/node/v8.h:2576:44: note: candidate: ‘v8::MaybeLocal<v8::Object> v8::Value::ToObject(v8::Local<v8::Context>) const’
2576 | V8_WARN_UNUSED_RESULT MaybeLocal<Object> ToObject(
| ^~~~~~~~
/home/un/.cache/node-gyp/12.14.0/include/node/v8.h:2576:44: note: candidate expects 1 argument, 0 provided
node-gyp 似乎是错误中的常见项目,npm 页面说它是“用于为 Node.js 编译本机插件模块”,这就是为什么我认为这是一个操作系统级别的问题。
所以应用程序已设置,但是当我尝试运行时
npm run dev
我得到以下信息:
> [email protected] dev /home/un/test
> nuxt
sh: /home/un//test/node_modules/.bin/nuxt: Permission denied
npm ERR! code ELIFECYCLE
npm ERR! errno 126
npm ERR! [email protected] dev: `nuxt`
npm ERR! Exit status 126
npm ERR!
npm ERR! Failed at the [email protected] dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/un/.npm/_logs/2020-01-03T15_35_00_168Z-debug.log
不熟悉 node/npm/NUXT 的人请注意:这只是标准的灌输过程。我这里没有自定义代码,这是很多人一直用来启动项目的,所以我不明白为什么它不工作(尤其是当它曾经工作时)。
我想知道“权限被拒绝”是否意味着这是一个用户访问问题,但我不知道如何检查。
在进行系统更新时,我还会收到一些关于文件较新的错误。
我将不胜感激任何帮助。如果您没有解决方案,那么至少就可能出现的问题或在哪里寻找解决方案提供一些建议。
如果您需要任何其他信息,请告诉我。
还不确定要添加哪些其他标签?文件错误、灌输、更新问题
编辑:文件权限:.nvm/versions/v12.14.0 中的节点是 -rwxr-xr-x 而 npm 和 npx 是 lrwxrwxrwx 链接到实际的 npm 与 -rwxr-xr-x 但实际的 npx 是 -rw-r --r-- (用户没有可执行文件)但我从未更改过这些,就像我说的那样,它曾经可以工作。node_modules中的每个文件夹都有drwxr-xr-x,我查看了一个文件夹,js文件是-rw-r--r--(但我假设它们是JavaScript,它们不需要执行......
Edit2:我刚刚注意到我的 node_modules 文件夹中没有 .bin 文件夹,也根本没有 nuxt 文件夹,但我认为这将是一个找不到文件的错误,而不是“权限被拒绝”。
然后我尝试chmod 775 -R node_modules
再次运行构建。这次它创建了 .bin 文件,但在 webpack 上仍然失败(node_modules/.bin/webpack: Permission denied),尽管这个链接是 lrwxrwxrwx 并且原始文件是 -rwxrwxr-x
虽然这使事情发生了变化,但我仍然无法启动该项目。我也认为这不是处理这个问题的正常方式。如果是,网站会说这是一项要求。
环境
Linux Mint 19.2 蒂娜 84_x64
安装
$curl -sL https://deb.nodesource.com/setup_10.x | sudo bash -
## Installing the NodeSource Node.js 10.x repo...
## Populating apt-get cache...
+ apt-get update
Hit:1 http://archive.canonical.com/ubuntu bionic InRelease
Hit:2 http://archive.ubuntu.com/ubuntu bionic InRelease
Hit:3 http://security.ubuntu.com/ubuntu bionic-security InRelease
Ign:4 http://packages.linuxmint.com tina InRelease
Hit:5 http://archive.ubuntu.com/ubuntu bionic-updates InRelease
Hit:6 http://archive.ubuntu.com/ubuntu bionic-backports InRelease
Hit:7 http://packages.linuxmint.com tina Release
Reading package lists... Done
## Confirming "tina" is supported...
+ curl -sLf -o /dev/null 'https://deb.nodesource.com/node_10.x/dists/tina/Release'
## Your distribution, identified as "tina", is not currently supported, please contact NodeSource at https://github.com/nodesource/distributions/issues if you think this is incorrect or would like your distribution to be considered for support
安装 Nodejs
$ sudo apt-get install nodejs
$ nodejs --version
v8.10.0
没有安装 LTS 版本 10x?
我正在尝试使用 NPM 安装节点包,但它只是给出了权限错误。昨天我可以毫无问题地安装软件包,但由于某种原因它已经停止工作。
asgeir@1e19udt0shu6:~/nodejs/first_test_app$ sudo npm install sharp
> [email protected] install /home/asgeir/nodejs/first_test_app/node_modules/sharp
> (node install/libvips && node install/dll-copy && prebuild-install) || (node-gyp rebuild && node install/dll-copy)
info sharp Downloading https://github.com/lovell/sharp-libvips/releases/download/v8.7.4/libvips-8.7.4-linux-x64.tar.gz
ERR! sharp EACCES: permission denied, open '/home/asgeir/nodejs/first_test_app/node_modules/sharp/9016-libvips-8.7.4-linux-x64.tar.gz'
info sharp Attempting to build from source via node-gyp but this may fail due to the above error
info sharp Please see https://sharp.pixelplumbing.com/page/install for required dependencies
gyp ERR! configure error
gyp ERR! stack Error: EACCES: permission denied, mkdir '/home/asgeir/nodejs/first_test_app/node_modules/sharp/build'
gyp ERR! System Linux 2.6.32-042stab133.2
gyp ERR! command "/usr/local/bin/node" "/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /home/asgeir/nodejs/first_test_app/node_modules/sharp
gyp ERR! node -v v10.16.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
npm WARN [email protected] No repository field.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] install: `(node install/libvips && node install/dll-copy && prebuild-install) || (node-gyp rebuild && node install/dll-copy)`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/asgeir/.npm/_logs/2019-07-17T06_16_33_097Z-debug.log
经过一番谷歌搜索,我发现一些倒灵魂的人遇到了同样的错误。他们显然是通过重新安装 NPM 和 NodeJS 让它工作的,但我没有成功。关于如何克服这个错误的任何想法?
CodiMD非常适合协作工作,但我想在我的笔记本电脑 (Ubuntu 18.04) 上使用它来做个人笔记,配置它可以在没有互联网连接的情况下工作并使用尽可能少的资源。手动安装似乎是一个很好的起点,但说明假设我不熟悉 Node、npm、数据库管理员等知识。我不需要 TLS、用户身份验证或与云服务的连接。
这是我到目前为止所拥有的:
sudo apt install -y nodejs npm sqlite3
sudo npm install -g node-gyp
sudo npm install -g yarn
# broken: sudo apt install -y libssl-dev
git clone https://github.com/codimd/server.git
cd server
sudo bin/setup
sudo vi config.json .sequelizerc
# in vi, copy 4 "db" lines from "development" to "production"
# in vi, disable "hsts" and "csp"
# in vi, what should go in the "url" line?
# in vi, what else needs modificaiton?
sudo npm run build
sudo npm start --production # fails: sequelize db:migrate && node app.js
# what is the best way to start CodiMD at boot?
简而言之,我正在寻找在 Ubuntu 上设置最少 1 个用户的 CodiMD 的详细说明。
我刚刚通过你们自己的帮助设法使我的服务状态处于活动状态,但是它仍然显示节点服务实际上没有运行。
简而言之,我知道我的节点应用程序正在运行,但出于所有密集目的,它没有按预期运行。
root@server:/etc/systemd/system# systemctl status parsoid.service
● parsoid.service - MediaWiki Parsoid Server
Loaded: loaded (/etc/systemd/system/parsoid.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2018-12-15 21:18:06 GMT; 29s ago
Main PID: 18799 (node)
Tasks: 9
Memory: 34.8M
CPU: 1.449s
CGroup: /system.slice/parsoid.service
└─18799 /usr/bin/node /var/www/gwart/mediawiki/extensions/VisualEditor/parsoid/bin/server.js
Dec 15 21:18:06 server.live-servers.net systemd[1]: Started MediaWiki Parsoid Server.
Dec 15 21:18:07 server.live-servers.net node[18799]: {"name":"parsoid","hostname":"server.live-servers.net","pid":18799,"level":30,"levelPath":"info/service-runner","msg":"master(18799) initializing 2 workers","time":"2018-12-15T21:18:07.189Z","v":0}
Dec 15 21:18:07 server.live-servers.net node[18799]: {"name":"parsoid","hostname":"server.live-servers.net","pid":18811,"level":60,"moduleName":"lib/index.js","levelPath":"fatal/service-runner/worker","msg":"Unexpected token ...","time":"2018-12-15T21:18:07.898Z","v":0}
Dec 15 21:18:08 server.live-servers.net node[18799]: {"name":"parsoid","hostname":"server.live-servers.net","pid":18799,"level":40,"message":"first worker died during startup, continue startup","worker_pid":18811,"exit_code":1,"startup_attempt":1,"levelPath":"warn/service-runner/master","msg
Dec 15 21:18:09 server.live-servers.net systemd[1]: Started MediaWiki Parsoid Server.
lines 1-15/15 (END)
root@server:/etc/systemd/system# netstat -tulpn | grep 8000
root@server:/etc/systemd/system#
root@server:/etc/systemd/system# ps ax | grep node
18799 ? Ssl 0:00 /usr/bin/node /var/www/gwart/mediawiki/extensions/VisualEditor/parsoid/bin/server.js
20820 pts/1 S+ 0:00 grep --color=auto node
[Unit]
Description=MediaWiki Parsoid Server
[Service]
ExecStart=/usr/bin/node /var/www/gwart/mediawiki/extensions/VisualEditor/parsoid/bin/server.js
Restart=always
User=root
Group=root
Environment=PATH=/usr/bin/node:/usr/local/bin
StandardOutput=syslog
StandardError=syslog
WorkingDirectory=/var/www/gwart/mediawiki/extensions/VisualEditor/parsoid
[Install]
WantedBy=multi-user.target
我相信这与这个问题有关:
Starting node application with node
works but not when starting it with/usr/bin/node
/usr/bin/env: ‘node\r’: No such file or directory
当我尝试运行某些东西时,我不断收到此输出。有想法该怎么解决这个吗?
我想制作一面智能镜子,在我决定购买树莓派之前,我想在我的旧电脑上预览它。我安装了 Raspberry pi(来自 Raspberry 主页的桌面版本)。一切都很好,当我从 apt 源包安装 nodejs 时,它没有别名(npm 的语法)。然后我关注了其他主题,他们说检查 uname -a 并转到 nodejs 主页下载兼容版本。
这是我的$uname -a Linux raspberry 4.9.0-8-amd64 #1 SMP Debian 4.9.130-2 (2018-10-27) x86_64 GNU/Linux
然后我去节点主页下载一个版本的 Linux Binaries (ARM) V6 解压并将它们全部复制到/usr/local/
并使用命令node -v
& npm
-v 检查它。我收到此错误消息/lib/ld-linux-armhf.so.3: No such file or directory
。
我以为是我的电脑不兼容,但是当我在 virtualbox 上尝试时,我仍然遇到同样的问题。