This code sets up a RESTful API using Express in Node.js for managing security controls, including functionalities to add, update, and delete controls, with data stored in memory and presented in a web interface with Bootstrap.
- Node.js installed on your machine
- download express body parser
- npm install express body-parser cors
- Postman installed for testing APIs (optional)
-
Clone the repository to your local machine:
git clone https://github.com/MiguelAngelHorta/Security-Controls-Inventory.git
-
Navigate to the project directory:
cd Security-Controls-Inventory
-
Install dependencies:
npm install express body-parser cors
-
Start the Express server:
node appAPI.js
-
The server will start running at
http://localhost:3000
. The JSON data in the inventory table can be viewed @ 'http://localhost:3000/controls' in the browser.
- Interact with the frontend by opening folder in Visual Studio and opening the 'indexAPI.html' file through
-
Interact with the backend server through bash through the following commands
(go to folder)
cd <folder location>
(add a control)
curl -X POST -H "Content-Type: application/json" -d '{"mainID":"5", "mainDescription":"Sample Control", "domain":"Sample Domain", "scope":"Yes"}' http://localhost:3000/controls
(update a control)
curl -X PUT -H "Content-Type: application/json" -d '{"mainDescription":"Updated Control", "domain":"Updated Domain", "scope":"No"}' http://localhost:3000/controls/5
(delete a control)
curl -X DELETE http://localhost:3000/controls/5
- fetchControls(): Fetches all controls from the server and populates the table.
- AddData(): Adds a new control to the server and updates the table.
- updateData(id): Fetches data of a specific control for editing.
- updateControl(id): Updates the data of a specific control on the server and in the table.
- deleteControl(id): Deletes a specific control from the server and updates the table.
- go to folder with files
- $cd foldername
- Initialize git
- $git init
- add files
- $git add .
- commit changes
- $git commit -m 'message'
- verify remote URL (if not already done)
- $git remote -v
- Pull Changes from remote repo to synchronize local with Github (if applicable)
- $git pull --rebase origin main -Resolve diverged branches (if applicable)
- $git config pull.ff only
- Pull changes from the remote repository again
- $git pull --rebase origin main
- push changes
- $git push -u origin main