til/applied-sciences/engineering/identifiers-and-mjs
identifiers-and-mjs.mdupdated 2026-07-223673 words
ダブルクリックで英日反転
Applied Sciences · Engineering

Identifiers, extensions, and the .mjs file

EN

An identifier is simply a name that points to one thing and distinguishes it from everything else — the same idea as a person's name or a license plate. In code, identifiers name variables and functions; in a filesystem, the extension names the file's type. A .mjs file is one specific case: JavaScript that Node.js must treat as an ES module.

What an identifier is

  • Identifier = a label that uniquely points to something, so you can refer back to it later.
  • In programming it names a variable (a labelled box holding data) or a function (a named block of processing): in let price = 100, the word price is the identifier.
  • The computer doesn't remember '100' loosely — it remembers 'the box named price holds 100', and price is how you fetch it again.

A file extension is a kind of identifier too

  • Extension = the '.xxx' at the end of a filename that signals what kind of file it is: .jpg (image), .pdf (document), .js (JavaScript).
  • Strictly, 'identifier' in programming means variable/function names, and extensions are a separate category — but both share one root idea: a name that distinguishes one thing from another.
  • The OS and other programs read the extension to decide how to open or run the file.

So what is .mjs?

  • .js is a JavaScript file — the language that runs websites and tools. .mjs is JavaScript that Node.js is required to treat as an ES module.
  • A module is a reusable part of a program: large software is split into parts (A, B, C…) and combined via import / export (commands that pass parts between files).
  • Node.js normally guesses module vs. script from package.json's 'type' field: the .mjs extension overrides that guess and forces ES-module handling, regardless of the setting.
  • This repo uses files like gen-notes-manifest.mjs to auto-build the note index — the .mjs makes import/export usable without extra config.
An identifier is a name that distinguishes one thing from others — that root idea covers variable names and file extensions alike. .mjs is a file extension that tells Node.js: 'treat this JavaScript as an ES module.'
応用科学 · エンジニアリング

識別子・拡張子、​そして​ .mjs ファイルの​正体

JP

識別子​(=identifier、​ある​ものを​他と​区別して​指し示す名前)は、​人の​名前や​車の​ナンバープレートと​まったく​同じ​発想だ。​プログラムの​中では​変数や​関数に​名前を​付け、​ファイルの​世界では​拡張子が​ファイルの​種類を​指し示す。​.mjs は​その​一例——Node.js​(=サーバー側などで​JavaScriptを​動かす実行環境)が​「ESモジュールと​して​扱え」と​判定する​ための​JavaScriptファイルだ。

識別子とは​何か

  • 識別子=ある​ものを​一意に​指すための​ラベル。​後から​それを​呼び出せるように​する​ための​名前。
  • プログラムでは、​変数​(=データを​入れておく​名前​付きの​箱)や​関数​(=処理のかたまり)に​名前を​付ける。​let price = 100 なら​ price が​識別子。
  • コンピュータは​「100」を​漠然と​覚えるのではなく​「price と​いう​名前の​箱に​100が​入っている」と​管理する。​price と​書けば​再び​その値を​取り出せる。

拡張子も​識別子の​一種

  • 拡張子​(=extension)​=ファイル名の​末尾の​「.○○」で、​その​ファイルが​何の​種類かを​指し示す。​.jpg​(画像)​・.pdf​(文書)​・.js​(JavaScript)。
  • 厳密には、​プログラミング用語の​「識別子」は​変数名・関数名を​指し、​拡張子は​別カテゴリ——ただし​「何かを​区別して​指す名前」と​いう​根っこの​発想は​同じ。
  • OS​(=基本ソフト)や​他の​プログラムは、​この​拡張子を​読んで​「どう​開くか・どう​実行するか」を​決める。

では​ .mjs とは?

  • .js は​ JavaScript​(=Webサイトや​ツールを​動かす言語)の​ファイル。​.mjs は​ Node.js が​必ず​「ESモジュール」と​して​扱う​JavaScript。
  • モジュール​(module)​=プログラムを​機能ごとに​分けた​再利用できる​部品。​大きな​ソフトを​部品A・B・C…に​分け、​import / export​(=部品を​他ファイルと​出し入れする​命令)で​組み合わせる。
  • Node.js は​通常 package.json の​「type」欄で​モジュールか​スクリプトかを​推測するが、​.mjs 拡張子は​その​推測を​上書きし、​設定に​関わらずESモジュール扱いを​強制する。
  • この​リポジトリでは​ gen-notes-manifest.mjs のような​ファイルで​ノート一覧を​自動生成している。​.mjs に​する​ことで、​追加設定なしに​ import/export が​使える。
識別子とは​「ある​ものを​他と​区別して​指す名前」​——この​根っこの​発想が、​変数名も​拡張子も​等しく​貫いている。​.mjs は​ Node.js に​『この​JavaScriptを​ESモジュールと​して​扱え』と​伝える​拡張子だ。
148 notestil