Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
json-file-object
Advanced tools
periodically persisting JSON-able objects into files (one per object)
A mockup of a db for a single "JSON"-able object, periodically stored in a file so it can be recovered after restart.
To install, do
> npm install json-file-object
var json_file_object = require("json-file-object");
var my_obj = json_file_object();
The reference stored in variable my_obj
is saved to the file
file_object.json
every 5 secs. If the file exists, the object under
the reference is initialized with the JSON parsed content of the file,
if not it is initialized to {}
.
The above defaults (for the file name, the interval, or the initial value) can be
specified by the parameters passed to the constructor function
returned by json_file_object = require("json-file-object")
. I.e.,
var my_obj = json_file_object()
really means:
var my_obj = json_file_object({value:{}, file:"json_file_object.json", saveEverySecs:5, forceNew:false});
If flag forceNew
is set, the old content of the file is ignored and the initial value of the returned object is set by the first argument.
The generator function returned by require("json-file-object")
, called
here json_file_object
, has following methods:
json_file_object.stop(obj)
- stops recording obj
to its filejson_file_object.stopAll()
- stops all recordingsjson_file_object.erase(obj)
- stops recording obj
and erases the corresponding filejson_file_object.eraseAll()
- stops all recordings and erases all corresponding filesFor more info, look into the code index.coffee
and tests
test.coffee
, re_test.coffee
, which are probably shorter than that
document.
You can not reassign a new reference to my_obj
and hope that the new value will be persisted. For example, if you do
my_obj = ["Hey"];
the old reference kept by my_obj
is lost, so any change to my_obj
, such as
my_obj.push("Ho");
will not be persisted (because the value under the old reference is being persisted). The logic here is somehow similar to exports
and module.exports
.
Also, notice that in order to properly terminate the node
process
using json-file-object
you will need to stop "persisting", e.g., by
calling json_file_object.stopAll()
.
FAQs
periodically persisting JSON-able objects into files (one per object)
We found that json-file-object demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.