Go to file
2022-10-19 11:38:14 +03:00
components upload files int repos 2022-10-19 11:38:14 +03:00
.gitignore add files into repos 2022-10-13 11:42:58 +03:00
codeExample.js connection /brigade-catalog 2022-10-18 08:08:30 +03:00
index.js upload files into repos 2022-10-10 15:28:26 +03:00
package-lock.json add files into repos 2022-10-13 23:24:17 +03:00
package.json connection /brigade-catalog 2022-10-18 08:08:30 +03:00
readme.md connection /brigade-catalog 2022-10-18 08:08:30 +03:00

Njsbacker

Njsbacker is framework for backend developing at node.js/express.js (in future versions can be supports any frameworks)

How it works?

Below you can see simple scheme as framework works: from session response get into Main class where or getting at Group and next into Method, or at Method Class where response data from http-params, Group and Session hadling at execution method. simple scheme of njsbacker work After init main logic, logic can be converted at express.js router or express.js server (app). Below you can see example code:

// ... another code
mainserverObject.server(
    '/api'  // mount path of api
).listen(8080, '127.0.0.1', async (err) => {
    if (err) {
        throw err;
    }
    else {
        console.log('SERVER RUNNED');
    }
});

Below you can see how responses from http/call-function hadless into reponse at scheme: simple scheme of njsbacker handling data an executing Http data or Data from call method gets into pre_execution binary function where checks data: syntax/missed or no: if all successfuly data get into Session/Group/Method execute method else throwing error.

Before work.

Before work you must install this package:

# for npm
npm install njsbacker
# for yarn
yarn add njsbacker

And import at yoy project

// from nodejs
const njsbacker = require('njsbacker');
// from typescript
import njsbacker from 'njsbacker';

(We will be use node.js)

General clases and objects

Main

Main class is main backend-application, mainbased skelet of project. Mainclass object containts methods, groups, sessionHandler, etc. For all works you must create your class from njsbacker.Main

const njsbacker = require('njsbacker');

class App extends njsbacker.Main {
    // ...
}

If you want handling your format errors, responses (default JSON) you must add methods into your body of class:

const njsbacker = require('njsbacker');

class App extends njsbacker.Main {
    errorHadler (error) {  // Handling and show errors at backend application.
		let errorData;
		let codeStatus = 400;
		if (error.name == "API Error") {
			errorData = {
				code    : error.message,
				details : error.data
			};
		}
		else {
			errorData = {
				name  : error.name,
				stack : error.stack
			};
			codeStatus = 502;
		}
		return {
			mainbody : { error : errorData },
			headers  : {
			    error : error.name
			},
			cookies  : {
			    error_rised_at : Math.round(new Date().getTime() / 1000)
			},
			// redirect_uri: '';  // if want redirect to another url
			code: codeStatus
		}
	}
}

errorHadler

Hadling and format errors.

Additional clases and objects

Examples