nodejs-node-red-1
v1.0.6
Published
NodeJS REST API server for receiving user imports and storing the user data in CSV.
Readme
NodeJS <--> Node-RED
Required software:
NodeJS - tested on (v14.20.0)
NPM - tested on (v9.4.1)
Node-RED - tested on (v2.2.2)
Extra software Postman for the API endpoint testing.
NodeJS server
The servers source code is located in te nodeJS-server folder.
The Node JS server is built by using the expressJS extension.
The main objective of the REST API server is to provide three API endpoints.
Server Parameters
- protocol: HTTP
- IP address: 127.0.0.1 or localhost
- port: 8081
Endpoints
- GET - /getUsers - The endpoint returns all users stored in the nodeJS-server/users.csv file.
The stored users will be in the response body in the following content:
{
"users": [
{
"userName": "Radvanyi Matyas",
"email": " [email protected]",
"address": " Rohovce 49 93030",
"creationTimestamp": " 7574861c3ec89941"
}
]
}- GET - /getUser?userName=<userName> - The endpoint will return information about the user specified in the Query parameter.
In case the user is not stored in the CSV file it will return an empty JSON.
Example response body:
{
"userName": "Radvanyi Matyas",
"email": " [email protected]",
"address": " Rohovce 49 93030",
"creationTimestamp": " 7574861c3ec89941"
}- POST - /postUsers
The /postUsers endpoints purpose is to enable insert of users ot a CSV file which the server controls. The usersData is passed in the requests body. Example input data:
{
"users":
[
{
"userName":"Radvanyi Matyas",
"email":"[email protected]",
"address": "Rohovce 49 93030",
"creationTimestamp": "7574861c3ec89941"
},
{
"userName":"Radvanyi Tamas",
"email":"[email protected]",
"address": "Rohovce 44 93030",
"creationTimestamp": "7574861c3ec89941"
}
]
}Installation
Clone the repository:
git clone [email protected]:Mradvanyi123/NodeJS-Node-RED.gitInstall packages in the directory NodeJS-Node-RED/node-JS-server/.
npm installStart server in the directory NodeJS-Node-RED/node-JS-server/.
npm startOr install the server with npm
npm i nodejs-node-red-1Usage:
const APIserver=require('nodejs-node-red-1')