Here is a blog project developed based on Node.js, using the lightweight Koa framework to build API interfaces.
Through this project, you can easily build a simple and efficient blog system, experience the development convenience of Node.js, gain an in-depth understanding of the powerful Koa2 middleware, and master how data flows between the front and back ends and is stored in the MySQL database.
This project is very suitable for friends who want to learn Node.js, as well as those who want to use Node.js to build a personal blog. It can also be used as an ideal practical project for computer major graduation thesis.
Project features include:
A clear layered architecture is designed to make the project structure clear at a glance and easy to maintain and expand.
A complete engineering configuration is adopted to improve development efficiency. Including eslint code specifications, environment variable management, automatic parameter verification, middleware error handling, etc., to ensure the efficiency and stability of project development and operation.
The project implements a comprehensive blog system with simple design but complete functions, covering the following modules:
Core functions :
Important features :
3.1. Clone project code
https://github.com/lfb/nodejs-koa-blog.git
3.2.Create database
Be sure to create the boblog database before starting the project. If you have not installed the database, please click MySQL to download. Please modify your local database name (DB_NAME) and database password (DB_PASSWORD) in the .env.development
file in the root directory. ).
# env.development / env.production 文件
# 数据库
DB_NAME = 'boblog'
DB_HOST = 'localhost'
DB_PORT = 3306
DB_USER = 'root'
DB_PASSWORD = 'bobo1024.'
The following is the execution database command:
# 登录数据库
mysql -uroot -p密码
# 创建 boblog 数据库
CREATE DATABASE IF NOT EXISTS boblog2
DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
3.3. Start the project
# 进入项目根目录
cd nodejs-koa-blog
# 安装依赖包
npm install 或者 yarn install
# 启动 Node.js Koa2 项目
npm run dev 或者 yarn dev
You will see the console output the startup address: http://localhost:5000
, and you are successful!
4.1. If there is no yarn environment, can npm be used?
Answer: Yes, it is recommended to use yarn. yarn is faster than npm, mainly because the installation version is unified.
4.2. An error occurs when starting the Koa2 project. What is the reason?
Answer: First, please check whether you used npm or yarn to install dependency packages. Then, please check again to ensure that the database is installed and create a new database: boblog. Please see the database configuration above. Finally, check the Startup > Print log to see if there is any error message.
4.3. ... For more questions, please go to Issues, or if you have any questions, please go to Issues to ask.
MIT, by LFB
If you like it or it is helpful to you, please click a star to encourage me. If you have better suggestions and opinions, please let me know. You can leave a message as Issues. Hope it helps you learn! Thanks! mutual encouragement!