Skip to content

Instantly share code, notes, and snippets.

@smikes
Last active August 29, 2015 14:10
Show Gist options
  • Save smikes/b4947876c4bba3fbf87e to your computer and use it in GitHub Desktop.
Save smikes/b4947876c4bba3fbf87e to your computer and use it in GitHub Desktop.
reading/writing UTF-8 encoded chars in node
> var fs = require('fs')
> fs.writeFileSync('foo', JSON.stringify({ä: 'Å'}))
undefined
> ^Z
[1]+ Stopped node
smikes$ cat foo
{"ä":"Å"}smikes$ fg
node
> buf = fs.readFileSync('foo')
<Buffer 7b 22 c3 a4 22 3a 22 c3 85 22 7d>
> buf
<Buffer 7b 22 c3 a4 22 3a 22 c3 85 22 7d>
> JSON.parse(buf)
{ 'ä': 'Å' }
> require('os').platform()
'darwin'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment