🌙基于node+express+mysql 快速开发脚手架

Overview

cxl-node-template

🌙 基于node+express+mysql 快速开发脚手架

项目介绍

适应前后端分离开发的一款基于node快速接口简单开发脚手架(模板),集成了mysql,redis的存储,一键式配置,模块层层分离,适应小型项目的后端开发框架。

  • 整合Node.js+express
  • 整合MySQL5,6数据库
  • 整合Redis缓存数据库
  • 文件单/多上传功能(附示例)
  • 统一返回值封装
  • 统一UUID生成
  • websocket整合

部署运行

1.克隆项目

git clone https://github.com/18696232390/cxl-node-template.git

2.安装依赖

cd cxl-node-template
npm install  # 或 npm i

3.启动访问

npm start

访问127.0.0.1:10317,您将会看到如下页面,证明启动成功

运行成功截图

4.相关配置

系统默认集成了MySQL和Redis(默认关闭)

4.1 修改mysql配置

找到文件 \config\baseConfig.js文件

修改sql对象改成您的数据库配置即可,showSql用来启动后运行时命令行里面是否显示执行的sql语句

 sql:{
        host:'127.0.0.1',
        port:'3306',
        user:'root',
        password:'root',
        database:'test',
        showSql:true // 是否显示sql
    },
4.2 启用和修改redis配置

找到文件 \config\baseConfig.js文件

修改redis对象即可,默认是不使用redis,若想使用,请修改isOpentrue即可!

用户名密码尚未实现

 redis: {
        isOpen: false,
        ip: '127.0.0.1',
        port: 6379,
        username: '',
        password: ''
    }

二次开发指南

开发文档完整版:https://18696232390.github.io/cxl-node-template/

1.接口开发

1.1 创建第一个接口

/src/api/ 下创建helloWorldApi.js,引入如下头部

const express = require('express');
const router = express.Router();
const apiUtils = require('../../utils/apiUtils')

router.get('/test',async (req, res) => {
  try {
      apiUtils.sendSuccessMsg(res,"HelloWorld")
  } catch (error) {
      apiUtils.sendErrorMsg(res)
  }
})

module.exports = router;
1.2 注册接口

/app.js里面

app.use('/test', require(__dirname + '/src/api/helloWorldApi'));
1.33.启动访问
http://127.0.0.1:10317/test/test

可以看到页面上返回

{
  "code": "1",
  "msg": "调用接口成功",
  "data": "HelloWorld",
  "request_time": 1618906315494
}

2.操作MySQL

2.1 引入MySQL工具类

系统已经默认初始化mysql连接,无需自己初始化

const dbUtils = require('../../utils/dbUtils')
2.2 查询数据

使用dbUtils.query(sql)进行查询

  var sql = "SELECT * FROM SYS_USER WHERE USER_NAME = '" + username + "' AND PASS_WORD = '" + password + "'";
  dbUtils.query(sql)
   .then(res=>{
       resolve(res)
   }).then(err=>{
       reject(err)
   })
2.3 更新数据

使用dbUtils.update(sql)进行更新/修改/删除

var sql = " DELETE FROM SYS_USER WHERE ID = '" + id + "' ";
  dbUtils.update(sql)
    .then(res => {
        resolve(res)
    }).then(err => {
        reject(err)
    })

3.Redis操作

3.1 引入redis工具类
const redisUtils = require('../../utils/redisUtils')

注意要开启redis功能

3.2 存入redis

语法:

redisUtils.set(key , 数据)

案例:

redisUtils.set(bizConst.userConst.REDIS_KEY, JSON.stringify(res))
3.3 取数据

语法:

redisUtils.get(值的key).then(res=>{
   // .. res为存入的数据
})

案例:

redisUtils.get(bizConst.userConst.REDIS_KEY).then(redisResult => {
  // 业务代码
})
3.4 删除数据

语法:

redisUtils.del(值的key)

案例:

redisUtils.del(bizConst.userConst.REDIS_KEY)

开发进度

功能名称 是否完成 完成时间
🌟 基本的node框架+解决跨域 2021年3月27日
🌟 整合Mysql 2021年4月17日
🌟 整合Redis 2021年4月17日
🌟 封装返回实体 2021年4月17日
🌟 封装mysql+redis 2021年4月17日
🌟 封装单/多文件上传 2021年4月17日
🌟 整合websocket 2021年4月20日
📌 封装mysql分页功能 待实现
📌 整合封装ElasticSearch 待实现
📌 整合封装相关OSS接口 待实现

参考

技术点 原创链接
redis简单使用 https://segmentfault.com/a/1190000015882650
单/多文件上传 https://github.com/acexyf/multerDemo/
You might also like...

一个基于node.js,express,socket.io的websocket非常棒的聊天室,代码简单很适合新手. A very nice websocket chat room based on node.js, express, socket.io. the code is simple, very suitable for novices

一个基于node.js,express,socket.io的websocket非常棒的聊天室,代码简单很适合新手.  A very nice websocket chat room based on node.js, express, socket.io. the code is simple, very suitable for novices

来来往下看,虽然教程又臭又长但是一步步地保姆式教学很简单的,毕竟我是真菜鸟嘛,当然什么都往细了说╮(╯_╰)╭ 一、使用方法 该教程内容所有指令都为Linux CentOS 7.x环境下指令,其他平台请您自行查询(⊙x⊙;) 1.下载node.js并下载Sakura_Chat_Room node.j

Jul 21, 2022

Socket.io-Express - A simple express project to learn how to use socket.io.

Socket.io-Express - A simple express project to learn how to use socket.io.

Socket.io Express A simple express project to learn how to use socket.io ✨ 👶 Simple project This is a small project that has been designed to be usab

Sep 25, 2022

Express typescript boilerplate using @types/node, @types/express

Express framework boilerplate in typescript.

Sep 21, 2022

An express-ve way to start an express project

Express-ve express starter An express-ve way to start an express project. Checkout a demo project here or Learn how to use express-ve here Are you sta

Mar 28, 2022

ORM for TypeScript and JavaScript (ES7, ES6, ES5). Supports MySQL, PostgreSQL, MariaDB, SQLite, MS SQL Server, Oracle, SAP Hana, WebSQL databases. Works in NodeJS, Browser, Ionic, Cordova and Electron platforms.

ORM for TypeScript and JavaScript (ES7, ES6, ES5). Supports MySQL, PostgreSQL, MariaDB, SQLite, MS SQL Server, Oracle, SAP Hana, WebSQL databases. Works in NodeJS, Browser, Ionic, Cordova and Electron platforms.

TypeORM is an ORM that can run in NodeJS, Browser, Cordova, PhoneGap, Ionic, React Native, NativeScript, Expo, and Electron platforms and can be used

Jan 3, 2023

A query builder for PostgreSQL, MySQL and SQLite3, designed to be flexible, portable, and fun to use.

knex.js A SQL query builder that is flexible, portable, and fun to use! A batteries-included, multi-dialect (MSSQL, MySQL, PostgreSQL, SQLite3, Oracle

Jan 4, 2023

A simple Node.js ORM for PostgreSQL, MySQL and SQLite3 built on top of Knex.js

bookshelf.js Bookshelf is a JavaScript ORM for Node.js, built on the Knex SQL query builder. It features both Promise-based and traditional callback i

Jan 2, 2023

:rocket: One command to generate REST APIs for any MySql Database.

:rocket: One command to generate REST APIs for any MySql Database.

Xmysql : One command to generate REST APIs for any MySql database Why this ? Generating REST APIs for a MySql database which does not follow conventio

Dec 30, 2022

TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, MariaDB, PostgreSQL and SQLite databases.

TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, MariaDB, PostgreSQL and SQLite datab

Dec 31, 2022

A pure node.js JavaScript Client implementing the MySQL protocol.

mysql Table of Contents Install Introduction Contributors Sponsors Community Establishing connections Connection options SSL options Connection flags

Jan 1, 2023

Next-generation ORM for Node.js & TypeScript | PostgreSQL, MySQL, MariaDB, SQL Server & SQLite

Next-generation ORM for Node.js & TypeScript | PostgreSQL, MySQL, MariaDB, SQL Server & SQLite

Prisma Quickstart • Website • Docs • Examples • Blog • Slack • Twitter • Prisma 1 What is Prisma? Prisma is a next-generation ORM that consists of the

Jan 2, 2023

An adapter-based ORM for Node.js with support for mysql, mongo, postgres, mssql (SQL Server), and more

An adapter-based ORM for Node.js  with support for mysql, mongo, postgres, mssql (SQL Server), and more

Waterline is a next-generation storage and retrieval engine, and the default ORM used in the Sails framework. It provides a uniform API for accessing

Jan 4, 2023

This is a demo sample of linking NODEJS via ORM and MYSQL

Demons(Demo of Nodejs with SQL) This is a demo sample of linking NODEJS with ORM and MYSQL Connecting Node to SQL is a hard task and not much help is

Apr 14, 2022

egg.js(jwt) + mysql(sequelize) + redis + docker + docker-compose + nginx + vue + element-ui 全栈获取省市区数据(统计局数据)【工具】项目,实现在docker环境中一键部署

Egg-spider Preview 线上预览地址 (https://ronaldoxzb.com/) admin admin Project description [后端]egg.js(jwt) + mysql(sequelize) + redis + docker + docker-compo

Sep 29, 2022

Database manager for MySQL, PostgreSQL, SQL Server, MongoDB, SQLite and others. Runs under Windows, Linux, Mac or as web application

Database manager for MySQL, PostgreSQL, SQL Server, MongoDB, SQLite and others. Runs under Windows, Linux, Mac or as web application

Database manager for MySQL, PostgreSQL, SQL Server, MongoDB, SQLite and others. Runs under Windows, Linux, Mac or as web application

Dec 30, 2022

Use real-time computing technology and web technology to build a big data Kanban l to solve the problem. Among them, practical technologies include MySQL, Kafka, Flink, Redis, Flask and Echarts

Use real-time computing technology and web technology to build a big data Kanban l to solve the problem. Among them, practical technologies include MySQL, Kafka, Flink, Redis, Flask and Echarts

实时计算(English Version) 运用实时计算技术、Web 技术构建一个大数据看板来解决问题。其中实用技术包括Mysql、Kafka、Flink、Redis、Flask和Echarts 目录 1.问题需求 2.方案分析 3.安装环境 4.环境启动命令和运行代码的方法 5.代码目录结构说明

Jan 8, 2022

NextJs + Spring Boot + MySQL

NextJs + Spring Boot + MySQL

iMusic Website View Demo Description This is a website to liste to music online build with backend Spring Boot, database MySQL, and frontend Nextjs. P

Nov 20, 2022

A MySQL Library for Node.js

A MySQL Library for Node.js

Mar 14, 2022

Ceci est un handler utilisant la librairie Eris qui est une alternative à discord.js et MySQL

DiscordEris-Bot-Handler Prérequis des connaissances avec MySQL des connaissances en javascript Configuration Ouvrir le fichier config.js et modifier c

Mar 30, 2022
Owner
Chen.js
Chen.js
NodeJS,express and mysql starter project

Node-express-mysql-starterproject NodeJS,express and mysql starter project Start with cloning the repo & Run npm i to download all the dependecies Aft

Nermine slimane 16 Dec 11, 2022
practice site to utilize node.js, Express, and mySQL

fishing_site practice site to utilize node.js, Express, and mySQL Run Locally create local instance of MySQL database. Run DB/fishing_Schema.sql to cr

Ryan Graue 1 Jan 22, 2022
A dockerized express mysql starter using typescript which iclude user management

A dockerized express mysql starter using typescript which iclude user management

Nimatullah Razmjo 2 Jan 26, 2022
A Restaurant (Table) Reservation API built with Node, TypeScript, Express, TypeORM, a MySQL DB, all running on Docker containers

Restaurant (Table) Reservation API A simple API for reserving tables at a restaurant. The API is based on the REST architectural style and uses Node.j

null 14 Oct 5, 2022
A Restaurant (Table) Reservation API built with Node, TypeScript, Express, TypeORM, a MySQL DB, all running on Docker containers

Restaurant (Table) Reservation API A simple API for reserving tables at a restaurant. The API is based on the REST architectural style and uses Node.j

null 14 Oct 5, 2022
Node.js Express + MySQL vulnerable boilerplate project

Node.js Express + MySQL vulnerable boilerplate project

null 13 Sep 16, 2022
A CRUD implementation using sequelize, mySQL, NODEJS, Express, JWT and other technologies.

A ideia do projeto é simular o funcionamento do backend de um blog através da implementação de uma aplicação em Node.js usando o pacote sequelize para

Vinicius Savordelli 6 May 11, 2022
Simple REST API using Express with TypeScript, PostgreSQL, and MySQL to practice the Clean Architecture by Uncle Bob.

Clean-Architecture Simple REST API using Express with TypeScript, PostgreSQL, and MySQL to practice the Clean Architecture by Uncle Bob. About This RE

Abdullah Adel 10 Oct 16, 2022
Blog application api in Node.js express.js sequelize ORM and MYSQL Database

Node Express Mysql Sequelise Blog System Api Node api with express mysql sequelise Usage To get started with this api follow the steps below $ git clo

Kaddu Livingstone 6 Nov 9, 2022
CRUD APIs in NodeJS, Express and MySQL

Create CRUD APIs in NodeJS, Express and MySQL This is a simple NodeJS, Express and MySQL CRUD API example. that allows you to create, read, update and

Hala Ziani 5 Oct 19, 2022