This is a simple shopping list application built with Node.js and Express.
- Clone the repository:
git clone https://github.com/fad11/shopping-app.git- Navigate to the project directory:
cd shopping-list-app- Install dependencies:
npm install express body-parser Start the server:
npm startTo run the tests for this application, use the following command:
npm test- 200 OK: This status code indicates a successful response, returning the list of products in the response body.
[
{
"id": 1,
"name": "Product 1",
"price": 100
},
{
"id": 2,
"name": "Product 2",
"price": 200
}
]
-
201 Created: When a new product is successfully created, this status code is used to indicate the successful creation of the resource. The newly created product is returned in the response body.
-
400 Bad Request: This status code is returned when the request is invalid or missing required fields.
{
"name": "Tea",
"quantityAvailable": 1,
"price": 4
}{
"name": "Tea",
"quantityAvailable": 1,
"price": 4,
"id": "vdngvya1q"
}-
200 OK: The product update operation is successful, and the updated product details are returned in the response body.
-
400 Bad Request: This status code is returned when the request is invalid or missing required fields.
-
404 Not Found: This status code is returned when the product with the specified ID is not found.
{
"name": "Tea",
"quantityAvailable": 2,
"price": 8,
"id": "vdngvya1q"
}{
"name": "Tea",
"quantityAvailable": 2,
"price": 8,
"id": "vdngvya1q"
}-
204 No Content: This status code indicates that the product deletion operation was successful, and there is no content to return in the response body.
-
404 Not Found: This status code is returned when the product with the specified ID is not found.
- 200 OK: The request to retrieve the shopping list is successful, and the list along with the total cost is returned in the response body.
{
"shoppingList": [
{
"name": "Tea",
"quantityAvailable": 1,
"price": 8,
"id": "vdngvya1q"
}
],
"total": 10
}-
201 Created: When a product is successfully added to the shopping list, this status code is used to indicate the successful addition. The response includes a message confirming the addition and the updated total cost.
-
404 Not Found: This status code is returned when the product with the specified ID is not found.
-
400 Bad Request: This status code is returned when the product is out of stock or alreadyy in shopping list.
{
"message": "Product added to shopping list",
"total": 8
}-
200 OK: The product removal operation from the shopping list is successful, and a message along with the updated total cost is returned in the response body.
-
404 Not Found: This status code is returned when the product with the specified ID is not found in the shopping list.
{
"message": "Product removed from shopping list",
"total": 0
}- 200 OK: The request to retrieve all promo codes is successful, and the list of promo codes is returned in the response body.
-
201 Created: When a new promo code is successfully added, this status code indicates the successful creation of the promo code. The newly added promo code details are returned in the response body.
-
400 Bad Request: This status code is returned when the request is invalid or missing required fields.
- 204 No Content: This status code indicates that the promo code deletion operation was successful, and there is no content to return in the response body.
-
200 OK: When a promo code is successfully applied to the shopping list, this status code indicates the successful application. The response includes a message confirming the application and the updated total cost.
-
404 Not Found: This status code is returned when the promo code with the specified ID is not found.
docker build -t nodejsapp:1.0.0 .docker run -d -p 3000:3000 nodejsapp:1.0.0This playbook is designed to deploy a Node.js application using Ansible. It automates the process of installing Node.js, npm, application dependencies, and starting the Node.js application.
- Ansible installed on the control machine.
- SSH access to the target servers.
hostsfile configured with the IP address(es) of the target server(s).ansible.cfgfile configured with necessary settings.
-
Clone this repository to your local machine:
git clone https://github.com/fad11/shopping-app.git
-
Navigate to the directory containing the playbook:
cd Ansible -
Update the
hostsfile with the IP address(es) of your target server(s). -
Update
ansible.cfgif needed, ensuring it points to the correct inventory file. -
Customize the playbook and roles according to your project's requirements.
-
Run the playbook:
ansible-playbook playbook.yaml
playbook.yaml: Main playbook file defining tasks to be executed.hosts: Inventory file containing IP addresses or hostnames of target server(s).ansible.cfg: Ansible configuration file specifying default settings.roles/nodejs/tasks/main.yml: Role containing tasks for installing Node.js, npm, application dependencies, and starting the Node.js application.
- Application Path: Update the path to your Node.js application in the
roles/nodejs/tasks/main.ymlfile. - Node.js Version: If you need a specific version of Node.js, you can modify the
nameparameter in theEnsure Node.js and npm are installedtask to include the version. - Application Dependencies: Adjust the
npm installcommand in the playbook to install your application's dependencies. - SSH User and Key: Modify the
ansible_ssh_userandansible_ssh_private_key_filevariables in thehostsfile according to your server setup.
The repository contains Terraform code to deploy an AWS infrastructure, including a VPC, subnet, internet gateway, route table, security group, SSH key pair, and an EC2 instance. The infrastructure is designed to host a server that can be accessed via SSH.
Before running the Terraform scripts, ensure you have the following prerequisites:
- AWS account with appropriate permissions
- Terraform installed on your local machine
- An SSH key pair generated (the public key should be provided as
id_rsa.pub) - AWS access key and secret key (provide these as sensitive variables)
variables.tf: Defines input variables used in the Terraform configuration, including AWS region, VPC and subnet CIDR blocks, instance type, SSH key path, access key, secret key, and more.output.tf: Defines the output of the Terraform deployment, specifically the instance ID of the deployed EC2 instance.main.tf: Contains the main Terraform configuration, including the provider block for AWS, resource definitions for VPC, subnet, internet gateway, route table, security group, SSH key pair, and EC2 instance.id_rsa.pub: Sample SSH public key for reference. Replace this with your own SSH public key.secret.tfvars: Sample file for sensitive variables (access_keyandsecret_key). Replace the placeholder values with your actual AWS access key and secret key.
- Clone the repository to your local machine.
- Update the
secret.tfvarsfile with your AWS access key and secret key. - Replace the
id_rsa.pubfile with your own SSH public key. - Open a terminal and navigate to the cloned directory.
- Initialize Terraform by running:
terraform init - Review the execution plan by running:
terraform plan -var-file=secret.tfvars - If the plan looks good, apply the Terraform configuration by running:
terraform apply -var-file=secret.tfvars - Confirm the deployment by typing
yeswhen prompted. - Once the deployment is complete, Terraform will output the instance ID of the deployed EC2 instance.
- You can now access your EC2 instance using the SSH key pair provided during deployment.
To clean up the resources created by this Terraform configuration, run:
terraform destroy -var-file=secret.tfvars
Confirm the destruction by typing yes when prompted.