×
HOME
INSTALLATION
COMMANDS
LINKS
Copied successfully
Final API CLI
The "final-api-cli" is a powerful command-line interface tool designed to simplify and accelerate the development of Node.js REST APIs. With this CLI, you can automatically generate a fully structured, best-practices-compliant REST API based on user inputs. The generated API comes pre-configured with essential features such as routes, controllers, models, and Docker support, making it ideal for both small-scale and enterprise-level applications.
Get Started
📦 Installation

Install final-api-cli globally using npm:

$ npm install -g final-api-cli
🛠️ Commands
Help
The help command is used to displays the list of available commands and their descriptions.
To execute help command run fac -h or fac --help

user@machine: ~ $ fac --help

Usage: index [options]


Final API CLI for creating a Node.js REST API


Options:

-v, --version output the version number

-i, --init [project-name] initialize a new project

-r, --route [route-name] create a new route

-c, --controller [controller-name] create a new controller

-m, --model [model-name] create a new model

-e, --endpoint [endpoint-name] create a new endpoint

-h, --help display help for command

Version
The version command is used to displays the current version of the CLI.
To execute version command run fac -v or fac --version

user@machine: ~ $ fac --version

1.0.2

Init
The init command is used to create a new API project with the given project-name.
To execute init command run fac -i [project-name] or fac --init [project-name]
This command will prompt you to select the type of database to be used in the project. The available options are SQL and NoSQL. If you select SQL, you will be asked to choose a database dialect from the following options: MySQL, PostgreSQL, SQLite, Oracle, SQLServer, or MariaDB. For the NoSQL database type, no further selection is required. After the database type and dialect (if applicable) are selected, the command will automatically create a new project directory with the specified project name, download the appropriate project template based on the database selection, and install the necessary packages.

user@machine: ~ $ fac --init demo

? Choose your database type: SQL

? Choose your database: MySQL

Template downloaded successfully.

Template extracted successfully.

Npm packages installed successfully.

Project setup complete!


In this example, the SQL database type is selected, and MySQL is chosen as the database dialect, with the project name set to demo. Below is the resulting project folder structure. You can explore the files within the directories by clicking on them. The project structure remains consistent for both SQL and NoSQL options.
  • demo
    • __test__
      • e2e
        • e2e.test.js
      • integration
        • integration.test.js
      • unit
        • file-download.test.js
        • file-upload.test.js
        • user.test.js
    • configs
      • database.config.js
      • index.js
      • jest.config.js
      • pm2.config.js
    • controllers
      • health.controller.js
      • index.js
      • user.controller.js
    • downloads
      • sample.download.txt
    • middlewares
      • auth.middleware.js
      • cors.middleware.js
      • error.middleware.js
      • file-upload.middleware.js
      • index.js
      • preflight.middleware.js
      • rate-limit.middleware.js
    • models
      • index.js
      • user.model.js
    • routes
      • health.route.js
      • index.js
      • user.route.js
    • utils
      • index.js
      • send-response.util.js
      • status-codes.util.js
    • .dockerignore
    • .env.example
    • .gitignore
    • Dockerfile
    • package-lock.json
    • package.json
    • README.md
    • server.js

Total Directories: 11

Total Files: 36


The REST API generated by Final API CLI is designed to be robust, scalable, and easy to maintain. It follows best practices for RESTful architecture, provides extensive support for Docker containerization, environment variable configuration, process management, and comprehensive testing, including unit, integration, and end-to-end tests. Below is a breakdown of some key endpoints provided by the generated API:
Health Check
GET
/api/health
Check the health status of the API.
Status code
200
Request body
none
Response data
{
"status" : string,
"data" :
{
"status" : string,
"uptime" : number,
"memoryUsage" : object,
"timestamp" : number,
},
"messages" : string[]
}
File Operations
POST
/api/upload
Upload a file to the server.
Status code
200
Request body
{
"file" : form-data,
}
Response data
{
"status" : string,
"data" : { }
"messages" : string[]
}
GET
/api/download/:file-name
Download a file from the server.
Status code
200
Request body
none
Response data
file data
User Management
GET
/api/users
Retrieve a list of all users.
Status code
200
Request body
none
Response data
{
"status" : string,
"data" :
[
{
"id" : number,
"name" : string,
"email" : string,
"password" : string,
"createdAt" : datetime,
"updatedAt" : datetime
}
],
"messages" : string[]
}
GET
/api/users/:id
Retrieve details of a specific user.
Status code
200
Request body
none
Response data
{
"status" : string,
"data" :
{
"id" : number,
"name" : string,
"email" : string,
"password" : string,
"createdAt" : datetime,
"updatedAt" : datetime
},
"messages" : string[]
}
POST
/api/users
Create a new user.
Status code
201
Request body
{
"name" : string,
"email" : string,
"password" : string,
}
Response data
{
"status" : string,
"data" :
{
"id" : number,
"name" : string,
"email" : string,
"password" : string,
"createdAt" : datetime,
"updatedAt" : datetime
},
"messages" : string[]
}
PUT
/api/users/:id
Update an existing user's information.
Status code
200
Request body
{
"name" : string,
"email" : string,
"password" : string,
}
Response data
{
"status" : string,
"data" :
{
"id" : number,
"name" : string,
"email" : string,
"password" : string,
"createdAt" : datetime,
"updatedAt" : datetime
},
"messages" : string[]
}
DELETE
/api/users/:id
Remove a user from the system.
Status code
200
Request body
none
Response data
{
"status" : string,
"data" :
{
},
"messages" : string[]
}
Route
The route command is used to generate a new route file with the given route-name.
To execute route command run fac -r [route-name] or fac --route [route-name]

user@machine: ~ $ fac --route demo

CREATED : 'demo.route.js' created successfully.

UPDATED : 'index.js' updated successfully.

Model
The model command is used to generate a new model file with the given model-name.
To execute model command run fac -m [model-name] or fac --model [model-name]

user@machine: ~ $ fac --model demo

CREATED : 'demo.model.js' created successfully.

UPDATED : 'index.js' updated successfully.

Controller
The controller command is used to generate a new controller file with the given controller-name.
To execute controller command run fac -c [controller-name] or fac --controller [controller-name]

user@machine: ~ $ fac --controller demo

CREATED : 'demo.controller.js' created successfully.

UPDATED : 'index.js' updated successfully.

Endpoint
Generates a new API endpoint with route, model, and controller.
The endpoint command is used to create a new API endpoint this will generate new route, model and controller file with the given endpoint-name.
To execute endpoint command run fac -e [endpoint-name] or fac --endpoint [endpoint-name]

user@machine: ~ $ fac --endpoint demo

CREATED : 'demo.route.js' created successfully.

UPDATED : 'index.js' updated successfully.

CREATED : 'demo.model.js' created successfully.

UPDATED : 'index.js' updated successfully.

CREATED : 'demo.controller.js' created successfully.

UPDATED : 'index.js' updated successfully.