50 个必备的 Node.js 命令大全

50 个必备的 Node.js 命令大全

Node.js 是一个强大的 JavaScript 运行时环境,用于构建高性能、可伸缩的网络应用程序。在日常开发中,掌握一些 Node.js 的命令可以极大提升工作效率。以下是 50 个必备的 Node.js 命令,让你更好地管理、调试和优化你的 Node.js 项目。

npm官网:https://npmjs.org/

官网文档:https://docs.npmjs.com

npm CLI commands:CLI commands | npm Docs

1. 检查 Node.js 版本

$ node -v

2. 检查 npm 版本

$ npm -v

3. 初始化一个新的 Node.js 项目

$ npm init

 4. 安装特定版本的 Node.js 包

$ npm install <package-name>@<version>

5. 全局安装 Node.js 包

$ npm install -g <package-name>

6. 在 package.json 中添加依赖

$ npm install --save <package-name>

7. 在 package.json 中添加开发依赖

$ npm install --save-dev <package-name>

 8. 卸载 Node.js 包

$ npm uninstall <package-name>

9. 查看全局安装的 Node.js 包

$ npm list -g --depth 0

10. 查看特定包的信息

$ npm show <package-name>

11. 更新所有全局安装的 Node.js 包

$ npm update -g

12. 更新特定 Node.js 包

$ npm update <package-name>

13. 查看已安装的 Node.js 包

$ npm ls

14. 运行 Node.js 文件

$ node <filename.js>

15. 在 Node.js REPL(交互式解释器)中运行代码

$ node

16. 安装 nodemon(自动重启应用程序)

$ npm install -g nodemon

17. 使用 nodemon 启动应用程序

$ nodemon <filename.js>

18. 在浏览器中打开应用程序

$ npm start

19. 指定环境变量启动应用程序

$ NODE_ENV=production node <filename.js>

20. 检查项目依赖的漏洞

$ npm audit

21. 自动修复依赖的漏洞

$ npm audit fix

22. 创建一个新的 Node.js 模块

$ npm init module

23. 在项目中使用 ESLint

$ npm install eslint --save-dev

24. 初始化 ESLint 配置

$ npx eslint --init

25. 在项目中使用 TypeScript

$ npm install typescript --save-dev

26. 使用 TypeScript 初始化项目

$ npx tsc --init

27. 在项目中使用 Babel

$ npm install @babel/core @babel/cli --save-dev

28. 初始化 Babel 配置

$ npx babel init

29. 在项目中使用 Webpack

$ npm install webpack webpack-cli --save-dev

30. 初始化 Webpack 配置

$ npx webpack init

31. 在项目中使用 Jest 进行测试

$ npm install jest --save-dev

32. 初始化 Jest 配置

$ npx jest --init

33. 在项目中使用 Express.js

$ npm install express --save

34. 在项目中使用 MongoDB

$ npm install mongodb --save

35. 在项目中使用 Mongoose

$ npm install mongoose --save

36. 在项目中使用 Socket.IO

$ npm install socket.io --save

37. 在项目中使用 Lodash

$ npm install lodash --save

38. 在项目中使用 Moment.js

$ npm install moment --save

39. 在项目中使用 Axios

$ npm install axios --save

40. 在项目中使用 React

$ npm install react react-dom --save

41. 在项目中使用 Redux

$ npm install redux react-redux --save

42. 在项目中使用 GraphQL

$ npm install graphql --save

43. 在项目中使用 Apollo Client

$ npm install @apollo/client --save

44. 在项目中使用 Passport.js 进行认

$ npm install passport --save

45. 在项目中使用 JWT 进行认证

$ npm install jsonwebtoken --save

46. 在项目中使用 Nodemailer 发送邮件

$ npm install nodemailer --save

47. 在项目中使用 PM2 进行进程管理

$ npm install pm2 -g

48. 启动应用程序并保持永久运行

$ pm2 start <filename.js>

49. 查看 PM2 进程列表

$ pm2 list

50. 停止特定的 PM2 进程

$ pm2 stop <app-id>

这些命令涵盖了 Node.js 开发中的各个方面,从管理依赖到启动应用程序,再到测试和优化。希望这个列表对于初学者和有经验的开发者都能有所帮助!

  • 33
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

波吉桑

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值