一、Express服務器入口文件index.js設置
// node 後端服務器
const router = require('./routes/router'); // 接口地址管理
const path = require('path');
const bodyParser = require('body-parser');
const express = require('express');
const app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
// 後端api路由
app.use(router);
// 監聽端口
app.listen(3002);
console.log('success listen at port:3002......');
二、數據庫配置
前提:電腦安裝mysql數據庫
在項目根目錄下創建一個config文件夾,然後下面創建兩個文件
1. db.js----用來添加mysql配置
// 數據庫連接配置
module.exports = {
host: 'localhost',
user: 'root', // 數據庫賬號
password: 'xxxxxx', // 數據庫密碼
database: 'demo_weekly', // 該項目的數據庫名稱
port: 3306,
multipleStatements: true
}
2. api.js----用來添加接口地址
let path = '/demo-weekly/back-end/api';
module.exports = {
// user-用戶管理
userLogin: path + '/user/login', // 用戶登錄
userLogout: path + '/user/logout', // 用戶登出
userAdd: path + '/user/add', // 新增用戶
userUpdateInfo: path + '/user/updateInfo', // 更新用戶信息
userUpdateState: path + '/user/updateState', // 更新用戶狀態
userDetail: path + '/user/detail', // 獲取用戶詳情
userList: path + '/user/list', // 獲取用戶列表
// weekly-週報管理
weeklyAdd: path + '/weekly/add', // 新增週報
weeklyUpdateInfo: path + '/weekly/updateInfo', // 更新週報信息
weeklyUpdateState: path + '/weekly/updateState', // 更新週報狀態
weeklyDetail: path + '/weekly/detail', // 獲取週報詳情
weeklyList: path + '/weekly/list' // 獲取週報列表
};
三、項目體驗鏈接
週報管理系統體驗鏈接:https://www.17sucai.com/pins/35488.html
本人前端程序員,長期混跡於各種前端開發中,現在專門爲前端熱愛者建了個微信羣,和大家一起分享自己在工作、學習中遇到的技術知識或問題,還有各種資料和課程,各位感興趣的可以加入哦~