Created
April 11, 2017 14:03
-
-
Save levelsio/cb4a4414ab2c2dd8e77ead5ae690f5c4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you are just going to read it you can do this in JS: