nodejs

nodejs note

base64

standard lib.

var enc = new Buffer("日本").toString('base64')
var dec = new Buffer(enc, 'base64').toString()

gzip

standard lib.

var zlib = require('zlib');
var bin = zlib.gzipSync("imaoka-san");
var dec = zlib.gunzipSync(bin).toString()

Buffer

https://nodejs.org/api/buffer.html#buffer_class_method_buffer_from_buffer
- String = immutable & not byte-array
- Buffer = mutable & byte-array

from fs / encoding

var ret = fs.readFileSync("./cp932.txt");
// ret is Buffer, raw bin-array
var iconv = require('iconv-lite');

// decord bin-array(cp932) to json strings
var js_str = iconv.decode(ret,'CP932');
// json strings to utf8
js_str = iconv.encode(cp932,'UTF8').toString();

npx ?

  • ./node_modules/.bin/(package-name)
  • $(npm bin)/(package-name)
  • Write npm-scripts @ package.json

npx more cool!

npm install pm2
npx pm2

  Usage: pm2 [cmd] app


  Options:

    -V, --version                    output the version number
    -v --version                     get version