'how can i store data in txt file using JavaScript and retrieve data

hi im building application and i need to store data in txt file and retrieve it the data is object like this .. .

[
  {
    "key": 0,
    "id": 1,
    "number": "1001",
    "name": "سلعة ملموسة",
    "offer_end_date": null,
    "offer_start_date": null,
    "components": [],
    "quantity": "9",
    "product": {
      "id": 1,
      "name": "سلعة ملموسة",
      "number": "1001",
      "product_id": null,
      "foreign_name": "Product",
      "can_be_sold": 1,
      "can_be_purchased": 1,
      "can_be_rented": 1,
      "available_on_pos": 1,
      "pos_quick_lunch": 1,
      "available_on_manufacture": 1,
      "product_category_id": 1,
      "product_unit_type_id": null,
      "location_id": null,
      "area_id": null,
      "discount_value": 10,
      "balance": null,
      "smallest_unit_id": 1,
      "smallest_unit_barcode": null,
      "smallest_unit_selling_price": 10,
      "smallest_unit_cost": null,
      "smallest_unit_selling_price_above": null,
      "smallest_unit_selling_price_above_price": null,
      "tax_value": 16,
      "state_id": 1,
      "warehouse_id": null,
      "product_type_id": 1,
      "product_policy_id": null,
      "tax_user_id": null,
      "user_id": null,
      "get_specification_on_lines": null,
      "is_products_has_expire_date": 1,
      "is_products_has_patch_number": 1,
      "is_products_has_serial_number": 1,
      "offer_end_date": null,
      "offer_start_date": null,
      "last_purchase_date": null,
      "last_purchase_purchase": null,
      "last_purchase_price": null,
      "last_purchase_discount": null,
      "created_by": null,
      "deleted_by": null,
      "approved_by": null,
      "approved_date": null,
      "approved_state_id": null,
      "note": null,
      "created_at": "2022-03-04T06:52:16.000000Z",
      "updated_at": "2022-03-04T06:52:16.000000Z",
      "deleted_at": null,
      "get_pos_product_componentss": [],
      "get_pos_product_components": [],
      "get_smallest_unit_id": {
        "id": 1,
        "name": "حبة",
        "foreign_name": "unit",
        "number": "1",
        "created_by": 1,
        "deleted_by": null,
        "approved_by": null,
        "approved_date": null,
        "approved_state_id": null,
        "note": null,
        "created_at": "2022-03-04T06:52:15.000000Z",
        "updated_at": "2022-03-04T06:52:15.000000Z",
        "deleted_at": null
      },
      "get_product_offers": []
    },
    "smallest_unit_selling_price": 10,
    "smallest_unit_selling_price_above": null,
    "smallest_unit_selling_price_above_price": null,
    "discount": 0,
    "allowed_discount": 10,
    "tax_value": 16,
    "unit": "حبة",
    "smallest_unit_id": 1,
    "note": null,
    "active": 1,
    "price": 104.39999999999999
  }
]

now this object i need to store it in file called text.txt how can i store the object inside the file .. and how can i retrieve the data using JavaScript .. thanks .. ive found solutions thats i can put the object in cookies but my problem with cookies they only allowing 4kb of data



Solution 1:[1]

never mind i found this solution .. first of store data in localStorage like this ..

 localStorage.setItem("orders", JSON.stringify(this.orders));

then access it like this ..

var orders = JSON.parse(localStorage.getItem('orders'));
console.log(orders);

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 softya