nodejs 服务器 anywhere 问题记录

anywhere 是一个基于 nodejs 的静态服务器。安装使用都很方便:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
// 安装
npm install anywhere -g
// 使用
anywhere
// 安装 npm install anywhere -g // 使用 anywhere
// 安装
npm install anywhere -g
// 使用
anywhere

一般情况下,以上两个命令就可以了。但是使用中还是会难免出现各种报错。

ssh 报错

具体的报错信息我忘记记录了。看报错信息大体上是与 ssh 有关。当在手机上使用 nodejs 的时候经常有这种报错。

解决方法是升级 nodejs 版本。虽然 nodejs 早就支持了 arm,但低版本的 nodejs 生态依然有很多问题。对于手机上 nodejs 的升级,我用的 n。(aidlux 里运行的 debian)

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
// 清除 npm 缓存
npm cache clean -f
// 安装 n
npm install n -g
// 安装最新版 nodejs
n latest
// 清除 npm 缓存 npm cache clean -f // 安装 n npm install n -g // 安装最新版 nodejs n latest
// 清除 npm 缓存
npm cache clean -f
// 安装 n
npm install n -g
// 安装最新版 nodejs
n latest

装好之后,关闭终端,重新打开就是最新版 nodejs 了。

listen EADDRINUSE: address already in use :::8000

这个报错是因为目标端口已经被占用。

解决方法是指定 anywhere 端口

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
anywhere -p 5001
anywhere -p 5001
anywhere -p 5001

Error: spawn xdg-open ENOENT

anywhere 运行的时候会默认打开浏览器,如果系统没有默认浏览器(比如服务器上),就会有这个报错。

解决方法是添加 -s 参数。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
anywhere -p 5001 -s
anywhere -p 5001 -s
anywhere -p 5001 -s

改用 http-server 了。