0.0.3 • Published 6 years ago
ornitojs v0.0.3
OrnitoJS
Command line interface to start a new nodejs API based on express framework with Ornito structure defined from past projects.
- async await functions
- email builder using sendgrid service
- jobs using cronjob
- resources creation from command line
- relational and non-relational databases
- eslint
- tests
- convention over configuration
- knex.js
Setup
Ornito JS
allow you to easily start an API and code oriented to modules. strives to be an easily embeddable and beautiful command line interface for Node.js.
Ornito JS
needs the following tools/techonologies to be able to start up.
- Nodemon
- Nodejs > 7.6.0
- Postgres
- Mongodb (if you're going to use it)
- Redis (if you're going to use it)
Note:
Ornito CLI
is still in active development, we want to deliver more features like eslint, iugu integration and more.
Command line
npm install -g ornitojs
ornito start
Running
npm start
npm test
npm run linter
Creating a new module
ornito module user
Database configuration
➡️ ./knexfile.js
development: {
client: 'postgresql',
connection: {
database: 'yourdb',
user: 'youruser',
password: 'yourpassword'
},
pool: {
min: 2,
max: 10
},
migrations: {
tableName: 'migrations'
},
seeds: {
directory: './seeds/dev/'
}
},
➡️ ./src/config/ENV.json
{
"db_host": "postgres://youruser:yourpassword@localhost:5432/yourdb",
"sendgrid_api_key": "",
"iugu": {
"url": "https://api.iugu.com/v1/",
"api_key": "",
"api_token": ""
},
"cloudinary": {
"cloud_name": "",
"api_key": "",
"api_secret": "",
"env_variable": ""
}
}
🔧 Module structure
- user
- tests
- user.spec.js
- user.model.js
- user.persistence.js
- user.schema.js
- user.service.js
- tests
💬 Structure description
- tests: We are using Jest to test our models, but you can test endpoints, services and schema validations in this folder. The test suit is called from
npm test
- model: Our entities represented by javascript classes and we call some database actions here, it might be mongoose calls or relational database calls
- persistence: Here you're able to require your database driver and start querying and inserting data to your choosen database.
- schema: We're using Joi to validate our models, so when we receive a request, if the payload validation is not correct, we throw an error.
- service: We can validate params, integrate with 3rd part services, create rules, call our models, etc.
💡 To do:
- create database if does not exist (node-postgres)
- show eslint options (standard, standard2, airbnb...)
- create job from CLI
- option to inform database settings while creating structure (user, password, host)
- implicit filters on routes