bulletproof-nodejs 正在参加 2021 年度 OSC 中国开源项目评选,请投票支持!
bulletproof-nodejs 在 2021 年度 OSC 中国开源项目评选 中已获得 {{ projectVoteCount }} 票,请投票支持!
2021 年度 OSC 中国开源项目评选 正在火热进行中,快来投票支持你喜欢的开源项目!
2021 年度 OSC 中国开源项目评选 >>> 中场回顾
bulletproof-nodejs 获得 2021 年度 OSC 中国开源项目评选「最佳人气项目」 !
授权协议 MIT License
开发语言 JavaScript
操作系统 跨平台
软件类型 开源软件
所属分类 Web应用开发
开源组织
地区 不详
投 递 者 首席测试
适用人群 未知
收录时间 2021-11-30

软件简介

Bulletproof Node.js architecture 🛡️

This is the example repository from the blog post 'Bulletproof node.js project architecture'

Please read the blog post in order to have a good understanding of the server architecture.

Also, I added lots of comments to the code that are not in the blog post, because they explain the implementation and the reason behind the choices of libraries and some personal opinions and some bad jokes.

The API by itself doesn't do anything fancy, it's just a user CRUD with authentication capabilities. Maybe we can transform this into something useful, a more advanced example, just open an issue and let's discuss the future of the repo.

Development

We use node version 14.9.0

nvm install 14.9.0
nvm use 14.9.0

The first time, you will need to run

npm install

Then just start the server with

npm run start

It uses nodemon for livereloading :peace-fingers:

Online one-click setup

You can use Gitpod for the one click online setup. With a single click it will launch a workspace and automatically:

  • clone the bulletproof-nodejs repo.
  • install the dependencies.
  • run cp .env.example .env.
  • run npm run start.

Open in Gitpod

API Validation

By using celebrate, the req.body schema becomes cleary defined at route level, so even frontend devs can read what an API endpoint expects without needing to write documentation that can get outdated quickly.

route.post('/signup',
 celebrate({
   body: Joi.object({
     name: Joi.string().required(),
     email: Joi.string().required(),
     password: Joi.string().required(),
   }),
 }),
 controller.signup)

Example error

{
 "errors": {
   "message": "child \"email\" fails because [\"email\" is required]"
 }
}

Read more about celebrate here and the Joi validation API

Roadmap

  • API Validation layer (Celebrate+Joi)
  • Unit tests examples
  • Cluster mode
  • The logging 'layer'
  • Add agenda dashboard
  • Continuous integration with CircleCI 😍
  • Deploys script and docs for AWS Elastic Beanstalk and Heroku
  • Integration test with newman 😉
  • Instructions on typescript debugging with VSCode

API Documentation

To simplify documenting your API, we have included Optic. To use it, you will need to install the CLI tool, and then you can use api exec "npm start" to start capturing your endpoints as you create them. Once you want to review and add them to your API specification run: api status -- review.

FAQ

Where should I put the FrontEnd code? Is this a good backend for Angular or React or Vue or whatever ?

It's not a good idea to have node.js serving static assets a.k.a the frontend

Also, I don't wanna take part in frontend frameworks wars 😅

Just use the frontend framework you like the most or hate the least. It will work 😁

Don't you think you can add X layer to do Y? Why do you still use express if the Serverless Framework is better and it's more reliable?

I know this is not a perfect architecture but it's the most scalable that I know with less code and headache that I know.

It's meant for small startups or one-developer army projects.

I know if you start moving layers into another technology, you will end up with your business/domain logic into npm packages, your routing layer will be pure AWS Lambda functions and your data layer a combination of DynamoDB, Redis, maybe redshift, and Agolia.

Take a deep breath and go slowly, let the business grow and then scale up your product. You will need a team and talented developers anyway.

展开阅读全文

代码

评论 (0)

加载中
更多评论
暂无内容
发表了博客
2018/07/14 16:22

Node.js-Webstorm2018配置nodejs

网上都是webstorm老版本的设置方法!根本就找不到以下配置项: 下面介绍2018版的配置方式。功能:使webstrom支持node.js语法检测及语法提示! 例如:配置前,没有任何提示 配置后 配置方法: 打开file->setting,并在搜索框输入node。在右边设置区域确认node.exe是否定位正确,并勾选Coding assistance for Node.js,最后点确认“ok”即可...

0
0
发表了博客
2018/03/15 13:47

nodejs

21、nodejs异步读写文件 https://blog.csdn.net/songmaolin_csdn/article/details/52910771 20、nodejs垃圾回收 node --max_semi_space_size=1 --max_old_space_size=10 1.js --production max_semi_space_size 32 16 max_old_space_size 1.4G 0.7g node --v8-options | grep max dong@ubuntu:~$ node --v8-options | grep max --gvn_iterations (maximum number of GVN fix-point iterations) --max_inlining_levels (maximum ...

0
0
发表于AI & 大数据专区
2014/03/21 20:22

Node.js

介绍 JavaScript 高涨的人气带来了很多的变化,以至于如今使用其进行网络开发的形式也变得截然不同了。就如同在浏览器中一样,现在的我们也可以在服务器上运行 JavaScript ,从前端跨越到后端,这样巨大的反差让人难以想象,因为仅仅在几年前 Javascript 还是如同 Flash 或者 Java applet 那样嵌入网页在沙箱环境中运行的小程序。 在深入Node.js之前,你可能需要阅读和了解,整个开发流程从客户端到服务端再到数据库的《JavaScr...

0
1
2018/11/19 09:52

Node.js

简单的说 Node.js 就是运行在服务端的 JavaScript。 Node.js 是一个基于Chrome JavaScript 运行时建立的一个平台。 Node.js是一个事件驱动I/O服务端JavaScript环境,基于Google的V8引擎,V8引擎执行Javascript的速度非常快,性能非常好。 。。。。。。 Node.js教程适用人群http://www.iis7.com/a/lm/yczmljgj/ 对于不会运用Python、PHP以及Java等动态编程语言的前端程序员来说,选择Node.js作为一个创建自己的服务的工具是非常明...

0
0
没有更多内容
加载失败,请刷新页面
点击加载更多
加载中
下一页
暂无内容
0 评论
0 收藏
分享
OSCHINA
登录后可查看更多优质内容
返回顶部
顶部