Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 16 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save levelsio/cb4a4414ab2c2dd8e77ead5ae690f5c4 to your computer and use it in GitHub Desktop.
Save levelsio/cb4a4414ab2c2dd8e77ead5ae690f5c4 to your computer and use it in GitHub Desktop.
#
# Building an MVP?
# Need a quick database you can set up in seconds?
# What about JSON?
#
# by @levelsio (with help from @marckohlbrugge, @oskarth, @maxdeviant and @kumailht)
# JS
db=[]
fs=require('fs')
fs.writeFileSync('db', JSON.stringify(db))
db=JSON.parse(fs.readFileSync('db'),'utf8')
# PHP #
$db=array();
file_put_contents('db',json_encode($db));
$db=json_decode(file_get_contents('db'),true);
# Ruby #
require "json"
db=[]
File.write "db.json", db.to_json
db=JSON.parse open("db.json").read
@franciscop
Copy link

If you are just going to read it you can do this in JS:

const db = require('./db.json');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment