1 Star 0 Fork 0

Alex / ubiquitous-nodejs

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

ubiquitous-nodejs

⚡ ubiquity-nodejs 是一个基于 node.js 的 web 脚手架。😘 支持模版渲染、Restful API、ORM 等特性,遵循 MVC 架构。

GitHub Workflow Status GitHub repo size Issues GitHub pull requests GitHub

GitHub followers GitHub forks GitHub stars GitHub watchers

如何部署项目?

仓库地址:

本地部署

  1. 直接使用 git 拉取项目源码,并进入项目根目录
git clone https://gitee.com/pudongping/ubiquitous-nodejs.git ubiquitous && cd ./ubiquitous
  1. 安装项目依赖包
npm install
  1. 填写配置信息
# 复制开发环境配置文件
cp ./config/development.js.example ./config/development.js

# 复制生产环境配置文件
cp ./config/production.js.example ./config/production.js

# 复制测试环境配置文件
cp ./config/test.js.example ./config/test.js
  1. 导入初始数据表

这里只是为了演示 restful api 的 CRUD 功能,故此创建了一个初始数据库。

# 连接数据库
mysql -h <your-mysql-host> -u <your-mysql-account> -p <your-mysql-password>;

# 导入初始数据表
source ./database/ubiquitous.sql;
  1. 启动项目

以下方式执行任意一条命令即可

# 直接使用 node 执行项目入口文件的方式
node --use_strict app.js

# 使用 npm 执行
# 运行开发环境
npm start
# 或者
npm run dev

# 运行生产环境
npm run prod

# 运行测试环境
npm run test
  1. 搭建完毕!enjoy it! ✌️

可以打开浏览器访问 localhost:9500 或者 127.0.0.1:9500 进行访问,即可看到首页欢迎语。

关于项目目录


├── LICENSE  License
├── README.md  项目说明文档
├── app.js  项目入口文件
├── bootstrap  项目启动目录
│   ├── boot.js  启动文件
│   ├── db.js  数据库封装
│   ├── rest.js  restful api 方法封装
│   ├── static-files.js  静态文件处理方法封装
│   └── templating.js  模版处理方法封装
├── config  配置文件目录
│   ├── development.js  开发环境配置文件
│   ├── development.js.example  开发环境配置文件模版
│   ├── production.js.example  生产环境配置文件模版
│   └── test.js.example  测试环境配置文件模板
├── constants  常量文件
│   └── ErrorCode.js  api 错误码常量
├── controllers  控制器目录
│   ├── auth  auth 模块目录
│   │   └── user_controller.js  用户控制器(这里作为演示 restful api 写的 demo)
│   └── home_controller.js  首页控制器 (这里作为演示模版调用写的 demo)
├── database  数据文件目录
│   └── ubiquitous.sql  初始化数据库文件
├── lib  工具目录
│   ├── api_error.js  自定义错误异常类
│   └── helper.js  助手函数
├── loader.js  项目加载文件(这里定义项目全局变量)
├── models  模型目录
│   ├── WebSite.js  站点模型文件
│   ├── auth  auth 模块模型目录
│   │   └── User.js  用户模型文件
│   └── model.js  自动化扫描加载所有的模型
├── package-lock.json  插件包描述锁文件
├── package.json  插件包描述文件
├── routes  路由目录
│   ├── api.js  restful api 路由目录
│   └── web.js  web 路由目录
├── services  服务层目录
│   └── auth  auth 模块服务层目录
│       └── user_service.js  用户服务层文件
├── static  静态文件目录
│   ├── css  样式文件目录
│   │   ├── googleapis-fonts.css
│   │   └── iview.css
│   ├── fonts  字体文件目录
│   └── js  js 文件目录
│       ├── iview.min.js
│       └── vue.min.js
└── views  视图层文件目录
    ├── base.html  视图基础文件
    ├── home  home 模块视图文件目录
    │   └── hello.html
    └── home.html  首页视图文件

项目所使用依赖包

插件包 作用
koa 使用 Koa2 作为 web 框架
koa-router 处理 url
koa-bodyparser 解析原始 request 的 body
nunjucks 模版引擎
cross-env 环境脚本的跨平台设置
mz 支持 Promise 的 fs 模块
mime 读取文件的 mime
mysql2 Node.js 的 mysql 驱动程序
sequelize Node.js 的 ORM 框架
moment 日期处理

使用演示

  • 如果需要使用模版引擎的方式,请查看 controllers/home_controller.js 文件。
  • 如果需要使用 api 的方式,请查看 controllers/auth/user_controller.js 文件。

感谢支持

如果你觉得本项目对你有所帮助,请帮忙给个 Star
如果你想贡献一份力量,欢迎提交 Pull Request

MIT License Copyright (c) 2021 pudongping Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

ubiquitous-nodejs is a web scaffold which is based on node.js 展开 收起
JavaScript 等 3 种语言
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/pudongping/ubiquitous-nodejs.git
git@gitee.com:pudongping/ubiquitous-nodejs.git
pudongping
ubiquitous-nodejs
ubiquitous-nodejs
main

搜索帮助