1、node.js是什么:就是一个javascript的后台版本,专门在服务器端执行
2、node.js一般不会独立来开发
node.js的用途:
1. 中间层
作为中间层的好处是:
- 安全
- 提高性能
- 降低主服务器的复杂度
2. 小型服务
3. 工具类开发(例如webpack)
* 中间层和中间件键是截然不同的,中间层是概念性的东西,中间键就是个库
node.js的优势:
1、便于前端入手
2、性能高(比如运算时)
3、利于和前端代码整合
node.js的搭建:
换源:http://npm.taobao.org/(淘宝镜像)
npm install -g cnpm --registry=https://registry.npm.taobao.org
cnpm
安装: cnpm install xxx(简写 cnpm i xxx)
删除: cnpm uninstall xxx(简写 cnpm un xxx)
* 有一些特殊的包只能用npm安装,cnpm安装不上
如何卸载低版本node.js?
1、卸载node本身、删除node.js的目录
2、手动删除node.js里的node_modules目录
3、手动删除c盘用户下的node_modules目录
查找安装地址可以在终端输入cmd -> where node
运行node.js程序:
1、目录
cd /
F:
2、运行
node 1.js
node.js引用包的步骤:
1、安装包
cnpm i multer
2、引入
const multer = require('multer');
3、使用
const http = require('http');
let server = http.createServer(()=>{ //请求
console.log('请求来了');
})
//监听
server.listen(8080);
在浏览器输入localhost:8080即可在终端收到console.log
监听: 等待客户端的链接
端口: 数字(例如8080)