安装Node.js
# 官网下载Node.js安装包(LTS版)
https://nodejs.org/zh-cn/
# 执行安装并验证是否成功
node --version
# npm
npm -version
npm -help
# cnpm
npm install -g cnpm --registry=https://registry.npm.taobao.org
cnpm -version
# yarn(速度快、安全、可靠)
https://yarnpkg.com/
npm install -g yarn
yarn -version
# npm 与 yarn 常用命令对比
npm init / yarn init
npm install / yarn
npm install --save / yarn add
npm install --save-dev / yarn add --dev
npm update / yarn upgrade
npm uninstall / yarn remove
npm install -g / yarn global add
npm update -g / yarn global upgrade
npm ls -g / yarn global list
npm uninstall -g / yarn global remove
创建node的http服务
const http = require("http");
const data = {
code:200,
data:{
name: "hello node.js"
},
msg:"请求成功"
}
http.createServer((request,response) =>{
response.writeHead(200,{"Content-Type":"application/json"});
response.end(JSON.stringify(data));
}).listen(8096);
console.log("server runing at http://localhost:8096/");
React的安装
# 全局安装create-react-app工具
npm install -g create-react-app
# 使用create-react-app工具搭建react工程
create-react-app projectName
# 启动react
npm run start // 或者 npm start // yarn start
# 构建打包
npm build // 或者 yarn build
R