Introduction
Getting Started
App Config File
Entity Schemas
NoLang Script
NoLang Endpoints
Microservices
Storage
Documents / App Config File
contents

App Config File

Each NoLang application needs one config file. The default config file name is app.json or app.json5. Then this app can be executed like bellow
nolang app.json
If the app config file name was equal the default name then the command can be executed without its name like bellow because nolang command will find the config file in the current route
nolang
Or if the app config file name was not equal the default name then it can be executed by its name like bellow
nolang theappconfigfile.json -d /path/to/dir

Format of config file

Content of app.json5 file (or any name) must be in JSON or JSON5 format like below:
{
 	//(string) The name of the app
	name : "app1" ,
	//(array|object) Schemas | Configuration of loading schemas
	schemas : ... ,
	//(object) Default storage config for app schemas
	storage : ... ,
	//(array) List of endpoints this app serves them
	endpoints : ... ,
	//(array) List of microservice clients to other services 
	//(other apps created with nolang with compatible endpoints)
	microservices : ... ,
	//(object) logger options
	logger : ... ,
	//(object) User configuration for this app
	user : ... ,
	//(object) CPU cores used in cluster, default is 1
	cluster : ... , 
}

  • name
  • name of this application

  • schemas
  • schemas can show list of all schemas of entities in this app directly like bellow,
    [
    	{
    		"$id": "entity1",
    		"properties": {
    			"Name": {
    				"type": "string"
    			},
    			"Family": {
    				"type": "string"
    			},
    			"Age": {
    				"type": "number"
    			}
    		}
    	},
    	{
    		"$id": "entity2",
    		"properties": {
    			"Address": {
    				"type": "string"
    			},
    			"Tel": {
    				"type": "string"
    			}
    		}
    	}
    ]
    Or it can be a configuration of how to loading schema definitions from files or database
    {
     	//(string) Type of schema loader, can be ("file","mongodb","mysql")
    	adapter : ""file"" ,
    	//(string) Path of the folder contains app schema files
    	path : ""./schemas"/* or c:/app1/schemas */" ,
    	//(boolean) Keeps an eye on the schema files and reload them if they have changed.
    	//(Don't set true in production environment!)
    	watch : false , 
    }

  • storage
  • storage is the default storage configuration for data of app entities. For example, if data of entities must be saved in a JSON file named data.json in the directory /data we must configure it as shown below
    {
    	"adapter": "file",
    	"path": "/app1/data/data.json"
    }
    Or if data of entities are in the database like MongoDB
    {
    	"adapter": "mongodb",
    	"url": "mongodb://localhost:27017",
    	"database": "app1",
    	"id": "_id"
    }

  • endpoints
  • The endpoints is an array of connectors that our app creates and serves to another programs, such as a web page that connects to our app. For more information see section NoLang Endpoints.
    [
    	{
    		"type": "http",
    		"port": 80,
    		"routes": [
    			{
    				"path": "/",
    				"type": "html",
    				"method": "post"
    			}
    		]
    	}
    ]

  • microservices
  • The microservices is a list of microservice clients to other apps or services. More info is at NoLang Microservices.
    {
    	"microservices": [
    		{
    			"name": "MSforApp2",
    			"type": "http",
    			"url": "http://localhost:1000"
    		},
    		{
    			"name": "MSforApp3",
    			"type": "socket",
    			"port": 2000
    		}
    	]
    }

  • logger
  • The log configuration must be set in logger.
    {
    	"logger": {
    		"files": {
    			"trace": "./logs/all.json",
    			"warn": "./logs/warns.json"
    		}
    	}
    }

  • user
  • user shows where is the storage of users' info for authentication in this app.
    {
     	//(boolean) If this app needs to authenticate (default is false)
    	authenticate : true ,
    	//(string) the $Id of the schema users information is stored
    	schema : "users" ,
    	//(string) name of field indicating username of users
    	usernameField : "username" ,
    	//(string) name of field indicating password of users
    	passwordField : "password" ,
    	//(string) name of field indicating roles assigned to user
    	rolesField : "roles" ,
    	//(object) jsonwebtoken config
    	jwt : {
    		"secret": "5Tyh&8%$S-=@",
    		"expiredIn": "2h"
    } ,
    	//(boolean) allow to set roles directly in script?
    	directRoles : ... , 
    }

  • cluster
  • cluster shows how many cpu cores can be used for clustering the app. Its default value is 1. For using all existing cpu cores set it to 0 or -1.
    {
    	"cluster": 0
    }