首页首页
前端
非前端
辅助
Github
前端
非前端
辅助
Github
  • 物联网

    • 基础知识
    • 米家相关
  • Node

    • Node基础
    • Node进阶
    • Node工具
    • Node脚本
  • Linux

    • Linux基础
    • Linux环境
  • 抓包

    • Whistle
    • Fiddler
  • Git

    • Git基础
    • Git进阶
    • GitLab CI/CD

1、Nodemon(监听更新)

监测项目中的所有文件,一旦发现文件有改动,会自动重启应用

npm install -g nodemon

node index.js 可换为 nodemon index.js

2、localtunnel(内网穿透)

npm install -g localtunnel

localtunnel 可以方便快捷的实现你的本地 web 服务通过外网访问,无需修改 DNS 和防火墙设置,其实现原理与 ngrok 类似

  • 启动:lt --port 8080 或 lt -p 8080

3、live-server (Web 服务器,自动刷新浏览器)

npm install -g live-server

简单的 js 配置文件

const liveServer = require('live-server');
const path = require('path');

const filePath = path.join(__dirname, '..'); // 文件所在路径
const fileUDID = 'sem-landpage-webapp'; // 根目录文件名标识符
const fileName = filePath.substring(
  filePath.indexOf(fileUDID) + fileUDID.length + 1,
  filePath.length
); // 最终得到的文件名字
const rootPath = path.join(__dirname, '../../'); // 根目录,因为查询common文件
const port = 8080; // 定义端口

const params = {
  port: port, // Set the server port. Defaults to 8080.
  host: '0.0.0.0', // Set the address to bind to. Defaults to 0.0.0.0 or process.env.IP.
  root: rootPath, // Set root directory that's being served. Defaults to cwd.
  open: `/${fileName}/src/html/index.html`, // When false, it won't load your browser by default.
  ignore: 'node_moudules', // comma-separated string for paths to ignore
};

liveServer.start(params);

4、Puppeteer(前端自动化测试)

5、Svrx(轻量级服务器)

npm install -g @svrx/cli
  • svrx // 在项目根目录启动 svrx

工程目录下建立 .svrxrc.js 或 svrx.config.js 文件,将命令行参数持久化下来:

module.exports = {
  port: 8777,
  livereload: true, // 自动热重载
  open: true, // 自动打开浏览器
};
  • svrx --localtunnel (内网穿透)
  • svrx --open=external --weinre --qrcode (远程调试移动端代码)

6、PM2 (node 进程管理)

npm install -g pm2
  • pm2 start app.js 启动进程/应用
  • pm2 stop app.js 结束进程/应用
  • pm2 list 查看当前正在运行的进程

7、Pkg(将 node 项目打包成可执行文件)

npm install -g pkg
  • pkg index.js 在项目根目录下执行
  • pkg -t win index.js 如果只想打包 windows 下的 exe,则加上-t 参数。win 即为打包成 windows 平台下的 exe 文件

8、whistle(抓包调试网页版)

npm install -g  whistle
  • w2 start -p 8899 // 启动,不设置端口默认使用 8899

9、npkill(删除 node_modules)

npm i -g npkill
  • npkill
最后更新: 2024/12/30 16:55
Prev
Node进阶
Next
Node脚本