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 @

5. 全局安装 Node.js 包

$ npm install -g

6. 在 package.json 中添加依赖

$ npm install --save

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

$ npm install --save-dev

 8. 卸载 Node.js 包

$ npm uninstall

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

$ npm list -g --depth 0

10. 查看特定包的信息

$ npm show

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

$ npm update -g

12. 更新特定 Node.js 包

$ npm update

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

$ npm ls

14. 运行 Node.js 文件

$ node

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

$ node

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

$ npm install -g nodemon

17. 使用 nodemon 启动应用程序

$ nodemon

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

$ npm start

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

$ NODE_ENV=production node

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

49. 查看 PM2 进程列表

$ pm2 list

50. 停止特定的 PM2 进程

$ pm2 stop

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

推荐链接

评论可见,请评论后查看内容,谢谢!!!
 您阅读本篇文章共花了: