1.1.1 • Published 4 years ago

gennode v1.1.1

Weekly downloads
3
License
MIT
Repository
github
Last release
4 years ago

GenNode

Author

Nathan Mersha

Installation

Gen node is available on npm, type:

$ sudo npm i -g gennode

and install it globally, now you can use it from the command line.

New on 1.0.0

  • Added gennode_authorization features as describe here

Introduction

Following the trendy naming paradigm of aa , here comes another one Server as a configuration. So what is SAAC about, well a very simple CRUD server has a set of properties that can be described in a simple configuration file. This properties could be one of the ones described below. This information is almost always found in the documentation accompanying the server. However there is an obvious limitation for documentations as such, and with good reason. That is one can read the in's and out's of the server, but one can't recreate it directly from the documentation (say if one wishes to spin up a new server with minor modifications to the first.) The main purpose of this module is to aid the developer to spin up a new REST CRUD project in less than a minute with all the durgeroies completed.

Naming

GenNode is short for Generate NodeJS.

Prerequisite and Note

  1. An installation of mongodb on the running machine is required for the tests to pass, and for the server to start. Make sure the mongod server is up and running. Guide on how to install and run MongoDB can be found here.
  2. Make sure to have a version of NodeJS above or equal to Version 4. Get NodeJs here
  3. The reverse proxy value in environment will be used inside a docker container, so avoid using values like 'http://localhost' or 'http://127.0.0.1, since this would effectively point to the container itself.
  4. Server and model names will be changed to their corresponding cammel case format according to this module.

CLI

RUN $ gennode --help for a list of available commands.

initialize (init)

$ gennode init

Creates a new genNode configuration file with interactive prompt.

sample (s)

$ gennode s

Generates a sample genNode configuration file for a hero academy.

generate (gen)

$ gennode gen -i <configFilePath> -o <outputPath>

Initializes a new server by the provided gennode config file.

options

--input, -i (Required) : Input to the gennode config file path, sample for a config file can be found below or simply run $ gennode init

--output, -o (Required) : Output path where the server files will be generated in.

Configuration

*The gennode configuration file is a simple javascript file exporting an object. Default name gennode.config.js*

Note

On some debian platforms there seems to be a problem while installing dependencies, generating apidoc and running test. So after you generated all the files run the following commands inside the root folder of the generated code in order.

$ npm install

$ npm run apidoc

$ npm run test

This will insure all of the files are generated.

Main

Main configuration field options.

OptionDescriptionDefaultType
serviceNameName of the serviceSample gen node serverString
serviceDescriptionA small description of what your service doesThis service is generated by gennode...String
authorService authorGen NodeString
copyrightCopyrightCopyright : Current DateString
runningModeService running modetest_modeString
licenceService LicenceMITString
versionVersion0.0.1String
repoURLRepository urlhttp://github.comString
baseURLVersion/serviceString
runServerRunns server after file generation is completed.falseBoolean
modelsList of models[]Array
dependantServicesDependant servicesDefault values hereObject
environmentEnvrionment variablesDefault values hereObject
authenticationHeader authentication typeDefault values hereObject
includeApiReqLibApi request librarytrueBoolean
certificatePathPath to root and client certificateDefault path hereObject
mongodbIncludes mongodb docker file in server configurationtrueBoolean
nginxGenerates a nginx proxy configuration filetrueBoolean
testTests the generated api, creates test and coverage report using Mocha, Chai and MochawesometrueBoolean
dockerTests docker files for the server.trueBoolean
jenkinsGenerates CI pipeline for the server.trueBoolean
postmanGenerates postman collection filetrueBoolean
elkLoggerInserts elk stack logger using the bunyan libfalseBoolean
enableProxyGenerate Nginx configuraiton filetrueBoolean
readMeGenerates readme file for the server.trueBoolean
documentationGenerates documentation powered by ApiDoctrueBoolean
instanceApp instance (A value of 0 will run the server in cluster mode utilizing all logical cores)1Number
commitCommits the generated file.trueBoolean
Dependant Services

Dependant service

OptionDescriptionDefaultType
endPointsList of endpoint to ping before initializing the service[]Array [String]
abortIfFailIf true server wont start if ping response code is 4 or 5falseBoolean
Authentication

Authentication options

OptionDescriptionDefaultType
typeAuthentication typeBearerString
headerKeyAuthentication header keyAuthenticationString
Certificate

Certificates path

OptionDescriptionDefaultType
rootPath to root certificatenullString
clientPath to client certificatenullString
clientKeyPath to client keynullString
Environment

Envrionment variables passed

OptionDescriptionDefaultType
DEBUGConsole output view for valid values*String
PORTServer running port3300Number
MODEServer running modetest_modeString
MONGODB_URLMongodb running urlmongodb://localhost:27017/serviceString
REVERSE_PROXYReverse proxy addresshttp://localhostString
COLLECTION_RETURN_SIZECollection return size24Number
ELEMENT_IN_PAGEElements in pagination return default value12Number
ELASTIC_SEARCH_URLElastic search endpinthttp://localhost:9200String
LOG_STASH_PORTLog stash port5000Number

Note You can add other environment variables here too.

Model

Model configuraion field options.

OptionDescriptionDefaultType
optionsoptionsOptions fieldObject
fieldsdefault fieldsfirstModified : {type : Date}, lastModified : {type : Date}Object

Model options (Valid option for model options key)

OptionDescriptionDefaultType
enableRouteIf true the model will have a CRUD endpoint.optionsBoolean

Field

Model field configuration options.

OptionDescriptionDefaultType
typeField type, any Mongoose type is valid"String"String
queryUsingIf true, will be able to query using this key in get requeststrueBoolean
publicVisibilityIf true, field will be visible on public call, will be hidden otherwise.trueBoolean
verifyOnCreateIf true, field will be verified on create.falseBoolean
editableOnUpdateIf true, field will be editable on update call.trueBoolean
visibleOnPaginationIf true, field will be visible in pagination calls.trueBoolean
es_indexedIf true, field will be indexed in elasticsearchtrueBoolean

Naming Conflict

Model names are converted to camel case, view this module for how the conversion happends. This could create conflict when at runtime when the naming is clearly not similar at configuration. (_example sample-name and sample_name will both be converted to sampleName at runtime) So avoid using similar names as such.

Sample Configuration

Sample gennode configuration file Postman documentation for my hero academy can be found here

/**
 * @author              Gen Node
 * @name                Gen Node
 * @module              gennode.config.js
 * @description         Default gennode configuration file
 * @kind                Config
 * @copyright           2018 Gen Node
 */

module.exports = {

    serviceName : 'Hero Academia',
    serviceDescription : "Teacher and student hero registry for Hero Academia",
    author : 'Young Midoria',
    copyright : `Copyright : 2018`,
    runningMode : 'test_mode',
    licence : 'MIT',
    version : '0.0.1',
    repoURL : "http://github.com",
    baseURL : '/heroAcademia',
    runServer : false,
    models : [
        {
            options : {
                name : 'Teacher'
            },
            fields  : {
                name : {type : "Number" , es_indexed : true},
                age : {type : "Number", es_indexed : true},
                gender : {type : "String"},
                followers : {type : "Array"},
                superPower : {type : "String" , es_indexed : false},
                costume : {type : "String"},
                powerGrade : {type : "String"},
                tournament : {type : "ObjectId", ref: "Tournament"},
                history : {type : "ObjectId", ref: "History"},   angerLevel : {type : "Number"},
                optimismLevel : {type : "Number"}
            }
        },

        {
            options : {
                name : 'Student'
            },
            fields  : {
                name : {type : "Number" , es_indexed : true},
                age : {type : "Number", es_indexed : true},
                gender : {type : "String"},
                powerClass : {type : "String"},
                superPower : {type : "String" , es_indexed : false},
                costume : {type : "String"},
                powerGrade : {type : "String"},
                tournament : {type : "ObjectId", ref: "Tournament"},
                history : {type : "ObjectId", ref: "History"},
                wins : {type : "Number"},
                loss : {type : "Number"},
                draw : {type : "Number"}
            }
        },

        {
            options : {
                name : 'Tournament'
            },
            fields  : {
                name : {type : "Number" , es_indexed : true},
                wins : {type : "Number"},
                loss : {type : "Number"},
                draw : {type : "Number"}
            }
        },

        {
            options : {
                name : 'History'
            },
            fields  : {
                angerLevel : {type : "Number"},
                optimismLevel : {type : "Number"},
                enemyDefeat : {type : "Number"},
                archNemesis : {type : "String"},
                battleGroundDefeat : {type : "Number"},
                enemyCapture : {type : "Number"},
                alive : {type : "Boolean"}
            }
        }

    ],

    dependantServices       : { // todo dependant services goes here
        endPoints               : [
            'http://hero_league.com',
            'http://villain_league.com'
        ],
        abortIfFail             : false
    },

    environment             : {
        DEBUG : "*",
        PORT : 3300,
        MODE : "test_mode",
        MONGODB_URL : "mongodb://localhost:27017/heroAcademia",
        REVERSE_PROXY : "http://localhost",
        COLLECTION_RETURN_SIZE : "24",
        ELEMENT_IN_PAGE : "12",
        ELASTIC_SEARCH_URL : "http://localhost:9200"

    },

    // Defines authentication header key and type for api requests
    authentication          : {
        type : 'Bearer',
        headerKey : 'Authentication'
    },

    includeApiReqLib        : true, // If true will include library for requesting outside api call
    certificate             : {
        root : null,
        client : null,
        clientKey : null
    }, // Some path to a certificate if request will be made using https.

    // Defines related containers
    elasticSearch : true,
    mongodb : true,
    nginx : true,

    minify : false,

    test : true,
    docker : true,
    jenkins : true,
    elkLogger : true,
    enableProxy : true,
    readMe : true,
    documentation : true,
    instance : "1",
    commit : true,
    commitMessage : 'Initial commit, generated by gennode.'
};

Generated files

Gennode generated files and directories.

NameDescription
apidocsGenerated api documentation
configGenerated server configuration file
controllerRoute controller files
coverageTest coverage report
dalData access layer for models
libLibraries
lib-constantError codes and other service related constants.
lib-helperApi requester and controller helper modules
lib-helper-apiApi requester libraries, if certificate is provided it will be copied in the cert directory.
lib-helper-othersController helper module
lib-middlewaresInitializer middleware
modelGenerated models
node_modulesNode modules
reportTest report
testTest suite files (dummy data and url generator module is also located here)
.dockerignoreDocker ignore file
.envEnvironment file
.gitignoreGit ignore file
app.jsApplication start file
docker-compose.ymlDocker compose file
DockerfileDocker file
package.jsonPackage file

Upcoming features

  • Multilevel schema support
  • User management service
  • Minify
  • Stress test

Contributing

If you have anything in mind, that you think is would be awesome to include in the generated server files, feel free to create an issue here, or fork the project.

1.1.1

4 years ago

1.1.0

4 years ago

1.0.3

4 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.5.0

5 years ago

0.4.0

5 years ago

0.3.14

5 years ago

0.3.13

5 years ago

0.3.12

5 years ago

0.3.11

5 years ago

0.3.10

5 years ago

0.3.9

5 years ago

0.3.8

5 years ago

0.3.7

5 years ago

0.3.6

5 years ago

0.3.5

5 years ago

0.3.4

5 years ago

0.3.3

5 years ago

0.3.2

5 years ago

0.3.1

5 years ago

0.3.0

5 years ago

0.2.6

5 years ago

0.2.5

5 years ago

0.2.4

5 years ago

0.2.3

5 years ago

0.2.2

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.8

5 years ago

0.1.7

5 years ago

0.1.6

5 years ago

0.1.5

5 years ago

0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago