2.0.3 • Published 4 years ago
nk-node v2.0.3
NK-Node
NK Central Libraries for NodeJS
How to install the library
npm i nk-node --save
How to include the library
const NK = require( "nk-node" );
How to use express
The express server can also be the SSL server (like a local web server), provide the location based on the domain name from let's encrypt
NK.xpr.load();
NK.xpr.load( "mydomain.com" );
NK.xpr.add( "get", "/user/:id", ( res, ip, requestedDATA, cookieOrSession, filesPosted, hostname ) => {
//the res item is the same as always
//ip is the Source IP of the request
//requestedDATA is the paramaters, already formatted, in the request, in this example you can use requestedDATA.id the data is auto formatted to an object regardless or source
//cookieOrSession is the object of the cookie or override session function
//filesPosted is the object of the files posted from the request
//hostname is the name of the host in the request. this is useful when using virtual hosts in the same node core
if( parseInt( requestedDATA.id ) > 0 ) {
res.json( { user: "valid" } );
} else {
res.status( 400 ).json( { user: "invalid" } );
}
});
The express server can also process user authentication
NK.xpr.load( "mydomain.com" );
NK.xpr.add( "get", "/user/:id", ( res, ip, requestedDATA, cookieOrSession, filesPosted, hostname ) => {
//the res item is the same as always
//ip is the Source IP of the request
//requestedDATA is the paramaters, already formatted, in the request, in this example you can use requestedDATA.id the data is auto formatted to an object regardless or source
//cookieOrSession is the object of the cookie or override session function
//filesPosted is the object of the files posted from the request
//hostname is the name of the host in the request. this is useful when using virtual hosts in the same node core
if( parseInt( requestedDATA.id ) > 0 ) {
res.json( { user: "valid" } );
} else {
res.status( 400 ).json( { user: "invalid" } );
}
}, ( headers ) => ( headers.auth == "isvalid" ) );
Happy Coding!
2.0.3
4 years ago
2.0.2
4 years ago
2.0.1
4 years ago
1.1.12
4 years ago
1.1.9
4 years ago
1.1.11
4 years ago
1.1.10
4 years ago
1.1.8
4 years ago
1.1.7
4 years ago
1.1.6
4 years ago
1.1.5
4 years ago
1.1.4
4 years ago
1.1.3
4 years ago
1.1.2
4 years ago
1.1.1
4 years ago
1.0.26
4 years ago
1.0.25
4 years ago
1.0.24
4 years ago
1.0.23
4 years ago
1.0.22
4 years ago
1.0.21
4 years ago
1.0.19
4 years ago
1.0.18
4 years ago
1.0.17
4 years ago
1.0.16
4 years ago
1.0.15
4 years ago
1.0.14
4 years ago
1.0.13
4 years ago
1.0.12
4 years ago
1.0.11
4 years ago
1.0.9
4 years ago
1.0.8
4 years ago
1.0.7
4 years ago
1.0.6
4 years ago
1.0.5
4 years ago
1.0.4
4 years ago
1.0.3
4 years ago
1.0.2
4 years ago
1.0.1
4 years ago
1.0.0
4 years ago