创建项目[名为back-table]
create-react-app back-table
进入项目根目录
cd back-table
ls命令查看目录下的文件列表
README.md node_modules package.json public src yarn.lock
安装antd
npm install antd --save-dev
安装redux
npm install redux --save
开发后台接口[express + mongodb]
安装express
npm install express --save
1.根目录下创建server目录,存放服务端代码
2.server/下新建server.js
/*----- /server/server.js ------ */
const express = require('express');
const app = express();
//开发get接口
app.get('/', function(req, res) {
res.send('hello world')
})
//开发post接口
// app.post('/', function(req, res) {
// res.json('...')
// })
app.listen(3000,function () {
console.log('node app start at port 3000')
});
使用nodemon监听路由和相应内容,自动重启
npm install -g nodemon //全局安装nodemon
//运行服务端文件可使用 -- nodemon server.js
下载安装mongoDB
安装homebrew[镜像]
/usr/bin/ruby -e "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/install)"
我安装中报了如下错误
Error: homebrew-core is a shallow clone.
解决方式:删除homebrew-core后更新即可
cd /usr/local/Homebrew/Library/Taps/homebrew
rm -rf homebrew-core
brew upgrade
cd "$(brew --repo)/Library/Taps/"
rm -rf homebrew
mkdir homebrew && cd homebrew
git clone git://mirrors.ustc.edu.cn/homebrew-core.git
配置homebrew
Homebrew通常用来下载软件的,但它在安装软件时非常慢。为了提升安装速度,需要更改 Homebrew 的安装源,将其替换成国内镜像。
- 必备设置
//替换 brew.git
git -C "$(brew --repo)" remote set-url origin https://mirrors.ustc.edu.cn/brew.git
//替换 homebrew-core.git
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
- 按需配置
//替换 homebrew-cask.git
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git
//替换homebrew-bottles【终端是bash】
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile
//替换homebrew-bottles【终端是zsh】
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.zshrc
source ~/.zshrc
Homebrew简介
Homebrew 主要由四个部分组成: brew、homebrew-core 、homebrew-cask、homebrew-bottles,它们对应的功能如下:
- Homebrew 源代码仓库
- homebrew-core 核心源
- homebrew-cask 提供macos应用和大型二进制文件的安装
- homebrew-bottles 预编译二进制软件包
Homebrew常见用法
// 查询:
brew search 软件名
// 安装:
brew install 软件名
// 卸载:
brew uninstall 软件名
// 更新 Homebrew:
brew update
// 查看 Homebrew 配置信息:
brew config
使用官方脚本同样会遇到uninstall地址无法访问问题,可以替换为下面脚本:
/usr/bin/ruby -e "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/uninstall)"
安装mongoDB到本地
教程参考官网
我的安装目录 /usr/local/var/mongodb
- 启动mongodb
mongod --config/usr/local/etc/mongod.conf
- mongo启动服务
npm install mongoose --save-dev
adminMongo 可视化工具
$ git clone https://github.com/mrvautin/adminMongo
$ cd adminMongo
$ npm install
$ npm start