项目作者: nameer-rizvi

项目描述 :
Write, read, & delete JSON stored in a .txt file located in a project's root folder.
高级语言: JavaScript
项目地址: git://github.com/nameer-rizvi/jsontxt.git
创建时间: 2020-04-28T18:35:23Z
项目社区:https://github.com/nameer-rizvi/jsontxt

开源协议:

下载


jsontxt

Write, read, & delete JSON stored in a .txt file.

Installation

  1. npm i jsontxt

Usage

Require module:

  1. const jsontxt = require("jsontxt");

Write json:

  1. const json = [{ key: "value" }, "item"];
  2. jsontxt.write(json, { filename: "test" });
  3. // Writes JSON in a test.txt file located in the project's root directory [default].

Read json:

  1. const json = jsontxt.read({ filename: "test" });
  2. console.log(json);
  3. // [{ key: "value" }, "item"]

Delete file:

  1. jsontxt.delete({ filename: "test" });
  2. // Deletes test.txt file.

.txt Path

By default, PWD is the environment variable used to find a project’s root directory. If it is null or undefined, or if you’d like to save the .txt file in a different location, you can define an absolute path to host the file using the JSONTXT_PATH environment variable name.

.txt Name

By default, the name assigned to the .txt file is “json”. If you’d like to save the .txt file under a different name, you can define it using the JSONTXT_NAME environment variable name.