不依赖编辑器,启动本地服务器, 适用于同一局域网下,多设备查看前端静态项目。
AnyWhere是一款随启随用的静态文件服务器,可以随时随地将你的当前目录变成一个静态文件服务器的根目录。
步骤
-
安装node。
-
打开cmd,执行命令
$ npm install anywhere -g -
找到需要启动本地服务器的文件夹,执行命令
anywhere,默认浏览器将自动打开主页。或者根据提示在浏览器输入对应地址即可访问本地项目。
遇到的问题
-
全局安装anywhere 时报错
npm ERR! code EPERM npm ERR! syscall mkdir npm ERR! path C:\Program Files\nodejs\node_modules.staging npm ERR! errno -4048 npm ERR! Error: EPERM: operation not permitted, mkdir 'C:\Program Files\nodejs\node_modules.staging' npm ERR! { [Error: EPERM: operation not permitted, mkdir 'C:\Program Files\nodejs\node_modules.staging'] npm ERR! cause: npm ERR! { Error: EPERM: operation not permitted, mkdir 'C:\Program Files\nodejs\node_modules.staging' npm ERR! errno: -4048, npm ERR! code: 'EPERM', npm ERR! syscall: 'mkdir', npm ERR! path: 'C:\Program Files\nodejs\node_modules\.staging' }, npm ERR! stack: npm ERR! 'Error: EPERM: operation not permitted, mkdir 'C:\Program Files\nodejs\node_modules\.staging'', npm ERR! errno: -4048, npm ERR! code: 'EPERM', npm ERR! syscall: 'mkdir', npm ERR! path: 'C:\Program Files\nodejs\node_modules\.staging' } npm ERR! npm ERR! The operation was rejected by your operating system. npm ERR! It's possible that the file was already in use (by a text editor or antivirus), npm ERR! or that you lack permissions to access it. npm ERR! npm ERR! If you believe this might be a permissions issue, please double-check the npm ERR! permissions of the file and its containing directories, or try running npm ERR! the command again as root/Administrator.
npm ERR! A complete log of this run can be found in: npm ERR! C:\Users\admin\AppData\Roaming\npm-cache_logs\2020-11-17T08_46_12_126Z-debug.log
解决方法:
方法1:删除C:\Users{账户}\下的.npmrc文件,再重新安装。
方法2:执行
npm cache clean --force
- 安装完成后在文件夹下执行命令anywhere:无法加载文件 C:\Program Files\nodejs\node_global\anywhere.psl,因为在此系统上禁止运行脚本。
解决方法:
-
以管理员身份运行Window PowerShell。
-
执行命令
set-ExecutionPolicy RemoteSigned -
执行命令
get-ExecutionPolicy查看设置状态,提示RemoteSigned成功。