1. 程式人生 > 實用技巧 >使用React+redux+Node.js+MongoDB開發(一)

使用React+redux+Node.js+MongoDB開發(一)

1. 全域性安裝create-react-app

npm install -g create-react-app

2. 建立新專案

create-react-app my-app

3. cd my-app 進入專案目錄後,ls命令檢視目錄下的檔案列表

4. 安裝redux

npm install redux --save

5. 開啟create-react-app 的配置檔案

npm run eject

  彈出配置檔案,可以自定義配置webpack 

6. 使用express + mongodb開發web後臺介面

npm install express --save

專案根目錄下新建server資料夾,並建立server.js

const express = require('express'); //引入express
//新建app
const app = express();

app.get('/', function (req,res) {
    res.send('<h1>Hello world</h1>')
});

app.listen(9093, function () {
    console.log('node app start at port 9093')
});

7. 使用nodemon監聽路由和相應內容,自動重啟。使用命令全域性安裝

sudo npm install -g nodemon

使用以下命令執行服務檔案

nodemon server.js

8. 下載安裝mongoDB

https://www.mongodb.com/download-center?jmp=nav#community

mac上面按照https://brew.sh/index_zh-cn這個地址上面的,在命令列輸入

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

等待安裝brew完成後,再安裝MongoDB

brew install mongodb

9. 安裝antd

npm install antd --save