Function addObject

  • Parameters

    • filePath: string

      The path to the JSON file.

    • id: any
    • content: object

      The object to be added to the JSON file.


      • The addObject function adds an object to a JSON file by first checking if the file exists.
      • If the file does not exist, an error message is displayed. If the file exists, the function reads the existing data from the file,
      • appends the new object to the data, and then writes the updated data back to the file.

    Returns Promise<void>

    Example

    const filePath = "data.json";
    const id = 1;
    const content = { name: "John", age: 30 };
    addObject(filePath, id, content);

Generated using TypeDoc