Lad
Node.js framework made by a former @expressjs TC and @koajs team member. Built for @forwardemail, @spamscanner, @breejs, @cabinjs, and @lassjs.
Install / Use
/learn @ladjs/LadREADME
Table of Contents
- Features
- Get Started
- Architecture
- Principles
- Related
- Contributing
- Contributors
- Trademark Notice
- License
Features
Lad boasts dozens of features and is extremely configurable.
Microservices
These microservices are preconfigured for security, performance, and graceful reloading.
Front-end
- Browser linting using [eslint-plugin-compat][] and [browserslist][] (see .browserslistrc for the default config)
- [Pug][] template engine (you can easily use [Moon][], [Vue][], [React][], or [Angular][], though typically [you aren't going to need it][yagni])
- [Gulp][] (latest version 4.x)
- [Sass][]
- [PostCSS][] (with [font-magician][], [import-url][], [font-grabber][], [base64][], and [cssnext][] pre-configured)
- [Bootstrap][]
- [Font Awesome][font-awesome]
- [SpinKit][]
- [SweetAlert2][]
- [Dense][]
- [Waypoints][]
- [LiveReload][]
- …
Back-end
- Redis, sessions, and flash toast and modal [SweetAlert2][] messages (uses [ioredis][] which has support for [Cluster][redis-cluster], [Sentinel][redis-sentinel], and more)
- Koa-based webapp and API servers (uses HTTP/2 for production!)
- Pagination built-in (using [ctx-paginate][])
- RESTful API with BasicAuth and versioning
- Automated job scheduler with cron and human-readable syntax (backed by [Mongoose][] and [Bree][])
- Passport-based authentication and group-based (Unix-like) permissioning
- Stripe-inspired error handling
- Mongoose and MongoDB with common database plugins
- Email template engine with [Nodemailer][] and local rendering
- Proxy eliminates need for Nginx reverse-proxy or Apache virtual hosts
- Multilingual through built-in i18n translation support (see configuration)
- Automatic phrase translation with Google Translate
- Sitemap generator for simple SEO
- …
Translation
Finally a framework that solves i18n everywhere; complete with automatic translation.
- Translation constants built-in so you [don't repeat yourself][dry]
- Webapp error messages and templates are translated
- Emails are translated
- API responses are translated
- Database errors are translated
- Authentication errors are translated
- …
Email Engine
Our beautiful email engine uses [email-templates][] (which is also made by the creator of Lad)!
- Test your emails locally with automatic browser-rendering on the fly
- Automatically inlines CSS for cross-browser and cross-platform email client support
- Use [Bootstrap][] in your email template designs
- Reuse your existing CSS and webapp styling
- Use any template engine (defaults to Pug)
- [Render custom fonts in emails with code][custom-fonts-in-emails]
- [Add icons with Font Awesome with code][font-awesome-assets]
- [Automatically avoid email client caching][nodemailer-base64-to-s3]
- Include any image you want and it will be properly rendered
- Rids the need for awkward embedded image CID attachments
- …
Error Handling
We've spent a lot of time designing a beautiful error handler.
- Supports
text/html,application/json, andtextresponse types - User-friendly responses
- HTML error lists
- …
See [koa-better-error-handler][] for a complete reference.
Performance
- Compression and zero-bloat approach
- Stream-based file uploading
- Graceful reloading, shutdown, and reconnection handling
- Manifest asset revisioning
- Amazon S3 and CloudFront ready
- …
Security
- Database security plugins and helpers
- Automated tests and code coverage
- CORS, SameSite set to "lax" ([an alternative to CSRF][csrf-alternative]), CSRF (since [not all browsers][csrf-caniuse] support SameSite yet) XSS, and rate limited protection
- Dotenv support for environment-based configurations
- App, user, and request-based logging
- SSL-ready (see instructions below)
- …
Get Started
We strictly support Mac and Ubuntu-based operating systems (we do not support Windows).
Requirements
Please ensure your operating system has the following software installed:
-
[Git][] - see [GitHub's tutorial][github-git] for installation
-
[Node.js][node] (v10+) - use [nvm][] to install it on any OS
- After installing
nvmyou will need to runnvm install node - We also recommend you install [yarn][], which is an alternative to [npm][]
- After installing
-
[MongoDB][] (v3.x+):
-
Mac (via [brew][]):
brew tap mongodb/brew && brew install mongodb-community && brew services start mongodb-community. -
Ubuntu:
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6 echo "deb http://repo.mongodb.org/apt/ubuntu "$(lsb_release -sc)"/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list sudo apt-get update sudo apt-get -y install mongodb-org
-
-
[Redis][] (v4.x+):
-
Mac (via [brew][]):
brew install redis && brew services start redis -
Ubuntu:
sudo add-apt-repository -y ppa:chris-lea/redis-server sudo apt-get update sudo apt-get -y install redis-server
-
Install
[npm][]:
npm install -g lad
[yarn][]:
yarn global add lad
Usage
Create a project
lad new-project
cd new-project
Development
To begin, try typing npm start (or yarn start) on command line. This will display to you all the scripts you can run.
The start script (among many others) uses [nps][] and [nps-utils][] under the hood. This helps to keep scripts very developer-friendly, and rids the need to write in JSON syntax.
This script accepts a <task> argument, whereas a task of all will spawn, watch, and re-compile all of the microservices mentioned above.
Just open http://localhost:3000 for testing!
[npm][]:
npm start all
[yarn][]:
yarn start all
Debugging
-
DEBUG- debug using [debug][] output (widely adopted package in the community for debugging across all Node packages):DEBUG=* ... -
NODE_DEBUG- debug [node][] internal modules:NODE_DEBUG=* ... -
MONGOOSE_DEBUG- debug Mongoose raw database operation output:MONGOOSE_DEBUG=true ... -
TRANSPORT_DEBUG- debug Nodemailer transport:TRANSPORT_DEBUG=true ... -
REDIS_MONITOR- debug Redis usingMONITOR(uses [@ladjs/redis][ladjs-redis] and passestruefor themonitorargument):REDIS_MONITOR=true ... -
REDIS_FRIENDLY_ERROR_STACK- debug Redis with friendly error stack messages (see [showFriendlyErrorStack][show-friendly-error-stack] option of [ioredis][])REDIS_FRIENDLY_ERROR_STACK=true ...
Production
We strongly recommend using [SemaphoreCI][], [PM2][], and [Digital Ocean][do
