LoginSignup
3

More than 5 years have passed since last update.

fs.readFileSyncでエンコードの指定をしないとHogan.jsがつかえなかった件

Posted at

背景

STLファイルを吐き出そうとして、Hogan.jsのテンプレートを読み込んで、コンパイルしたらエラー。

fs.readFileSyncはエンコード指定の有無で返されるオブジェクトが変わる

APIの説明を読むと以下のような記述されていた。

If the encoding option is specified then this function returns a string. Otherwise it returns a buffer. 

エンコードの指定がされいないとHogan.jsでテンプレートとして読み込んだ
つもりでも、buffer型のため、charAtメソッドが無いとエラーとなる。

関連記事

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3