The Lad recommended in this issue is the best Node.js framework, made by former Express TC and Koa team members.
Lad feature
Lad has dozens of features and is very configurable.
Microservices
These microservices are pre-configured for security, performance, and elegant reloads.
- Webapp server → web.js
- API server → APi.js
- Job scheduler → bree.js
- proxy server → proxy.js
< Back end
- Redis, session, Flash toast, and schema SweetAlert2 messages (using ioredis that supports Cluster, Sentinel, etc.)
- Koa based webapp and API server (production using HTTP/2!)
- Built-in paging (use ctx-paginate)
- RESTful API with BasicAuth and version control
- Automated job scheduler with cron and human-readable syntax (supported by Mongoose and Bree)
- Passport-based authentication and group-based (Unix-like) licensing
- Stripe inspired error handling
- Mongoose and MongoDB with universal database plug-ins
- Email template engine with Nodemailer and local rendering
- Proxy eliminates the need for an Nginx reverse proxy or Apache virtual host
- Support for multiple languages via built-in i18n translation (see Configuration)
- Sitemap generator for simple SEO
< Performance
- Compression and zero expansion methods
- Stream-based file upload
- Elegant reload, close, and reconnect handling
- List Asset revision
- Ready Amazon S3 and CloudFront
Start using
Strict support for Mac and Ubuntu-based operating systems (not Windows).
< Requirements
Make sure you have the following software installed on your operating system:
- Git – see GitHub installation tutorial
- Node.js (v10+) – Install it on any operating system using nvm
- nvm needs to run after installation nvm install node
- It is recommended that you install yarn, which is an alternative to npm
- 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) "/ mongo - 3.4 - / - org multiverse" < / span > | sudo tee/etc/apt/sources list. D/mongo - org < span Class = "HLJS - number" > 3.4 < / span >. 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 project
lad new-project
cd new-project
First, try typing npm start(or) on the command line. yarn start This will show you all the scripts you can run.
This start script (and many others) uses nps and nps-utils in the background.
The script accepts an < task> Parameter, and a task all will generate, monitor, and recompile all of the above microservices.
Just open http://localhost:3000 and test!
npm:
npm start all
yarn:
yarn start all
< Debugging
- DEBUG- Debug using debug output (a widely adopted package in the community for debugging across all Node packages) :
DEBUG=* ...
- NODE_DEBUG- Debugs internal modules of a node:
NODE_DEBUG=* ...
- MONGOOSE_DEBUG- Debug Mongoose original database operation output:
MONGOOSE_DEBUG=true ...
- TRANSPORT_DEBUG- debug Nodemailer transport:
TRANSPORT_DEBUG=true
REDIS_MONITOR- Debug Redis using MONITOR (use @ladjs /redis and pass parameters) : truemonitor
REDIS_MONITOR=true ...
- REDIS_FRIENDLY_ERROR_STACK- Debug Redis with friendly error stack messages (see showFriendlyErrorStack option for ioredis)
REDIS_FRIENDLY_ERROR_STACK=true ...
Configuration
Environment variable
According to Twelve-Factor, we simplified the configuration of the Lad project with the dotenv configuration package named @ladjs/env.
We use the following three packages to manage configuration:
- dotenv-extended – allows us to use.env in a file called.env.schema
- mustache – allows us to use the Mustache template language in our configuration files. env.env.defaults
- dotenv-parse-variables – automatically parses the variable type process.env (e.g., FOO=4 will set process.env.FOO =4 as the Number variable type instead of a String)
The configuration is managed by the following in order of priority:
- File contents located in config/index.js (read process.env environment variable)
- Contents of the files in the directory config/environments/ (Setting default values for each environment, for example, you can use NODE_ENV=staging, It will load the config file/environments/staging. Js) < / li >
- Used to override defaults or set required environment variables (e.g. NODE_ENV=production)
- Environment configuration in.env
- Environment Settings in.env.defaults
The priority is the environment profile, the environment variables, and then the.env file.
Basically, if dotenv has detected that it was passed as an environment variable, it will not set the environment variable.
View the contents of the config folder and the default values of.env.defaults.
Continuous integration and code coverage
Here are the simple steps needed to set up SemaphoreCI using Codecov:
- Go to SemaphoreCI and sign up for a free account
- After pushing the repository to GitHub, add it as a project to SemaphoreCI
- Configure your project on SemaphoreCI using the following build Settings:
- Add your project on Codecov and copy the token to the clipboard
- Set and add CODECOV_TOKEN as the environment variable for your project to go to SemaphoreCI (using the contents from the clipboard)
- Run the test build on SemaphoreCI (” rebuild the latest version “) and check to make sure your code coverage report is uploaded correctly on Codecov
- Make sure your README.md file has properly rendered build status and code coverage tags (if your GitHub repository is private, you’ll need to use different tag links from each provider)
—END—
Open Source license: MIT license