原生nodejs寫博客后端

用原生nodejs寫一個簡單博客的后端,僅供學(xué)習(xí)用,實際開發(fā)中肯定用框架好,用原生寫一遍能更好幫助你理解nodejs原理,讓你使用nodejs更加得心應(yīng)手。

GitHub倉庫地址

https://github.com/rongliangtang/nodejs-for-blog-backend

項目實現(xiàn)

  • 數(shù)據(jù)庫開發(fā)
  • 接口開發(fā)
  • 登錄:cookie和session的配合來存儲登錄狀態(tài)
  • 日志記錄以及分析
  • 安全:防止sql注入,xss攻擊,密碼加密

項目數(shù)據(jù)庫設(shè)計

數(shù)據(jù)庫設(shè)計
數(shù)據(jù)庫設(shè)計

項目接口設(shè)計

接口設(shè)計

項目結(jié)構(gòu)解析

項目結(jié)構(gòu)

啟動前需要更改數(shù)據(jù)庫配置和安裝redis

數(shù)據(jù)庫配置在src/config/db目錄下,更改為你電腦上的數(shù)據(jù)庫配置</br>
mysql中運行以下代碼創(chuàng)建數(shù)據(jù)庫和數(shù)據(jù):

create database blog;
use blog;
create table user(
    id INT(11) auto_increment primary key,
    username VARCHAR(30) NOT null unique,
    password VARCHAR(30) NOT null
);
create table classification(
    id INT(11) auto_increment primary key,
    name VARCHAR(30) NOT null unique,
    number INT(11) default 0
);
create table article(
    id INT(11) auto_increment primary key,
    title VARCHAR(30) NOT null,
    content longtext NOT null,
    createtime bigint not null ,
    classification INT(11) 
);
insert into user (username,`password`) values ('admin','123456');
insert into user (username,`password`) values ('管理員','123456');
insert into classification (name,number) values ('分類1',2);
insert into classification (name) values ('分類2');
insert into article (title,content,createtime,classification) values('標(biāo)題1','內(nèi)容1',1111111111,1);
insert into article (title,content,createtime,classification) values('標(biāo)題2','內(nèi)容2',1112222222,1);

安裝和啟動redis參考</br>https://www.runoob.com/redis/redis-install.html</br>(注意啟動后cmd窗口不可關(guān)閉)

啟動前先安裝項目所需要的依賴

npm install

編譯運行

npm run dev
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容