nodejs-api-cli
![David](https://img.shields.io/david/kemboijs/nodejs-api-cli)
When developing API based application in NodeJS, it is not easy to set it up as easy as possible.
The application include but not limited to applications build using Express, Sails.js, kemboijs, Koa.js, hapi, AdonisJS, Nest.js etc.
We decided to build this library/utility to help faster set up your API based application.
In the fisrt release, We will focus on supporting Express, but will imrpove on other frameworks and also nodejs itself without use of frameworks.
Also, we will aim at building utility that can enhance faster development of upcoming applications, building controllers, middlewares and also fixing issues on migrations in the near future.
How to use
- Install:
npm i -g nodejs-api-cli
- Create app:
nodejs-api-cli init
- Follow the steps and select your options
- Run app:
npm start
- Drop tables:
npm run drop:db
- Create tables:
npm run create:db
- Run tests:
npm test
NB: When installing make sure you have admin priviledges otherwise, you will have to use sudo npm i -g nodejs-api-cli
Steps:
- Get help
nodejs-api-cli -- -h
or nodejs-api-cli help
- Get version of app
nodejs-api-cli -- -v
or nodejs-api-cli version
Edit Database details
Navigate to src/models/setup.js
, edit the database name, username or password.
You can also add these credentials to the .env
file.
DATABASE_URL="postgres://user:pass@example.com:5432/dbname"
TEST_DB="postgres://user:pass@example.com:5432/testdb"
NODE_ENV="development"
In your src/models/setup.js
file:
import dotenv from "dotenv";
dotenv.config();
const dbUrl = process.env.NODE_ENV === 'test' ? process.env.TEST_DB : process.env.DATABASE_URL;
const sequelize = new Sequelize(dbUrl);
You can now call or edit the database models. The created model is User, under src/models/user.js
Folder Structure (More updates expected)
├── src
│ ├─ config
| ├─ index.js
│ ├─ controllers
| ├─ index.js
| ├─ user.js
│ ├─ middlewares
| ├─ index.js
| ├─ user.js
│ ├─ models
| ├─ index.js
| ├─ user.js
| ├─ setup.js
| └─ routers
| ├─ index.js
| ├─ user.js
| └─ scripts
| ├─ createdb.js
| ├─ dropdb.js
| ├─ index.js
├── test
│ ├─ index.js
│
└── index.js
└── README.md
└── package.json
Contributors
How To Contribute
In general, we follow the "fork-and-pull" Git workflow.
- Fork this repo on GitHub
- Clone the forked repo locally
- Work on your fork
- Make your changes and additions
- Change or add tests if needed
- Add changes to README.md if needed
- Commit changes to your own branch
- Make sure you merge the latest from "upstream" and resolve conflicts if there is any
- Push your work back up to your fork
- Submit a Pull request so that we can review your changes
Licence
MIT