Server
The @uteamjs/node framework simplifies the creation of the RESTful API server on top of the Node.js and Express ecosystem. The server integrates seamlessly with the frontend @uteamjs/react. It can be used alone as a powerful RESTful API server.
Create Server Application
#Use uteam cli create command to setup the server application:
$ uteam create -a <application-name> -t node-application
where node-application is the standard server template from @uteamjs/template.
Add Package
#Add the package ‘crud-api’ using template ‘node-crud-api’:
$ uteam create -p crud-api -t node-crud-api
Folder Structure
#The follow structure will be created:
// / ... node_modules packages/ main/ config.json package.json server.js crud-api/ contact.js detail.js package.json
main Package
#There is a default main package to host the server process with the following files.
server.js
#Main entry point for the server application.
const { server } = require('@uteamjs/node')
const app = server.start()
...
const app = server.start()
...
To run the server application, change to the packages/main directory then:
$ node server
config.json
#JSON file used to configure the server behaviors.
{
"name": "main",
"address": "0.0.0.0",
"port": 8000,
"db": {
"type": "sqlite",
"file": ":memory:"
},
"localModule": ["system"],
"header": {
"Access-Control-Allow-Origin": "http://localhost:3000",
"Access-Control-Allow-Credentials": "true",
"Access-Control-Allow-Headers": "Content-Type, token"
},
"jwt": {
"disable": true,
"secretOrKey": "chr0n0"
}
}
"name": "main",
"address": "0.0.0.0",
"port": 8000,
"db": {
"type": "sqlite",
"file": ":memory:"
},
"localModule": ["system"],
"header": {
"Access-Control-Allow-Origin": "http://localhost:3000",
"Access-Control-Allow-Credentials": "true",
"Access-Control-Allow-Headers": "Content-Type, token"
},
"jwt": {
"disable": true,
"secretOrKey": "chr0n0"
}
}
address
Server address.
db
Object to define db connections,
type: [oracle | mysql | sqlite] - type of database
parameters are based on different types of databases.
header
Server response header.
jwt
JSON web token configuration
disable: true - Diable JWT
secretOrKey: Secret key for encryption
localModule
Modules under the packages/main/src folder
name
Server name
port
Port number server listens to.