node中npm的使用
nodejs 软件
注:终端按两次Ctrl C 退出node
node -v 查看node版本
npm -v 看npm版本
1.安装nodejs 自带了包管理器npm (node package manager)
npm install Bootstrap
好比 Python 自带pip pip install requests
2.在终端进入当前项目目录,然后初始化目录,会生成一个package.json的文件来管理我们的包()模块(js)
npm init 简写为 npm i
npm i --yes 直接生成package.json
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
{ "name": "day50", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "keywords": [], "author": "", "license": "ISC", "dependencies": { "bootstrap": "^3.3.7", "jquery": "^3.3.1" } }
3.下载当前项目依赖的包
npm install jquery@3.4.0 --save 或 npm install jquery@3.4.0 -S
自动生成 node_modules文件夹
注:从github上下载项目后,在终端cd到该项目目录,执行npm install 自动下载package.json中依赖的所有的包
卸载 npm uninstall jquery@3.4.0 --save 或 npm uninstall jquery@3.4.0 -S
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
{ "name": "happyfri", "version": "1.0.2", "description": "vue2-happyfri", "author": "cangdu <1264889788@qq.com>", "private": true, "scripts": { "dev": "node build/dev-server.js", "build": "node build/build.js" }, "dependencies": { "vue": "^2.1.0", "vue-router": "^2.1.1", "vuex": "^2.0.0" }, "devDependencies": { "autoprefixer": "^6.4.0", "autoprefixer-loader": "^3.2.0", "babel-core": "^6.0.0", "babel-loader": "^6.0.0", "babel-plugin-transform-runtime": "^6.0.0", "babel-preset-es2015": "^6.0.0", "babel-preset-stage-2": "^6.0.0", "babel-register": "^6.0.0", "babel-runtime": "^6.23.0", "chalk": "^1.1.3", "connect-history-api-fallback": "^1.1.0", "css-loader": "^0.25.0", "eventsource-polyfill": "^0.9.6", "express": "^4.15.3", "extract-text-webpack-plugin": "^1.0.1", "file-loader": "^0.9.0", "function-bind": "^1.0.2", "html-webpack-plugin": "^2.8.1", "http-proxy-middleware": "^0.17.2", "json-loader": "^0.5.4", "less": "^2.7.1", "less-loader": "^2.2.3", "opn": "^4.0.2", "ora": "^0.3.0", "semver": "^5.3.0", "shelljs": "^0.7.4", "style-loader": "^0.13.1", "url-loader": "^0.5.7", "vue-loader": "^10.0.0", "vue-style-loader": "^1.0.0", "vue-template-compiler": "^2.1.0", "webpack": "^1.13.2", "webpack-dev-middleware": "^1.8.3", "webpack-dev-server": "^1.16.2", "webpack-hot-middleware": "^2.12.2", "webpack-merge": "^0.14.1" }, "engines": { "node": ">= 4.0.0", "npm": ">= 3.0.0" } }
下载的包 是当前项目的依赖包 如当前项目依赖 jquery + bootstrap npm i jquery --save npm i bootstrap --save 当前项目的依赖包 dependencies:{
"bootstrap": "^3.3.7",
"jquery": "^3.3.1"
} 压缩、丑陋化 前端三大工具: grant gulp webpack4.0 npm run dev npm i webpack@4.0 --save-dev 开发环境下的依赖包 devDependencies:{
"webpack": "^1.13.2",
"webpack-dev-middleware": "^1.8.3",
"webpack-dev-server": "^1.16.2",
"webpack-hot-middleware": "^2.12.2",
"webpack-merge": "^0.14.1"
}
放弃 PHP,选择 Node.JS 的 8 个理由!
PHP 因为有开源免费、语法简单、拓展性强等众多优点,一度成为 Web 开发领域最受欢迎的语言。淘宝、雅虎、新浪等大型门户网站,也都选用了 PHP 作为其开发语言。
但凡事都有两面性,PHP 的缺点同样很明显:代码重用率低、不擅长递归、对多线程支持不够好、缺乏标准框架与编码规范……- Node.JS 能降低开发环境的复杂性;
- Node.JS 在前端和后端开发中使用统一语言;
- Node.JS 只要求在服务器上安装;
- Node.JS 更好地体现了关注点分离,耦合度更低;
- Node.JS 使用 Apache / Nginx 代理;
- Node.JS 更容易找到合适的程序包;
- 未来五到十年内,Node.JS 都不会过时;
- Node.JS 保留了标准的 GIT 工作流程,适用于大多数代码编辑器。