クリップボードにコピーしました!
created-2025/11/13
updated-2026/03/15
前書き
このリポジトリは、nodeコマンドを実行してインストールした外部パッケージに記述された関数を実行する入門向けの解説です
インストールする必要のあるコマンド
クイックスタート
上記のコマンドをインストール済みの方は、以下のコマンドを実行してリポジトリからダウンロード後、ディレクトリを移動し、nodeコマンドを実行して関数が出力する文字列を確認してみてください
ubuntu
git clone https://github.com/trygfmi/node_executeExportFunction
cd node_executeExportFunction
cd work-directory_execute-export-function
npm init -y
npm install ../install_execute-export-function
cat ../install_execute-export-function/index.js
cat index.js
node index.js
出力結果
hello npm command world
hello export function
macos
macports
source ~/bashrc_folder/macports_alias
git clone https://github.com/trygfmi/node_executeExportFunction
cd node_executeExportFunction
cd work-directory_execute-export-function
npm init -y
npm install ../install_execute-export-function
cat ../install_execute-export-function/index.js
cat index.js
node index.js
出力結果
hello npm command world
hello export function
windows
WSL2
git clone https://github.com/trygfmi/node_executeExportFunction
cd node_executeExportFunction
cd work-directory_execute-export-function
npm init -y
npm install ../install_execute-export-function
cat ../install_execute-export-function/index.js
cat index.js
node index.js
出力結果
hello npm command world
hello export function
MSYS2 MINGW64
git clone https://github.com/trygfmi/node_executeExportFunction
cd node_executeExportFunction
cd work-directory_execute-export-function
npm init -y
npm install ../install_execute-export-function
cat ../install_execute-export-function/index.js
cat index.js
node index.js
出力結果
hello npm command world
hello export function
実行手順
ubuntu
クリックして詳細を開く
事前確認
以下のコマンドを端末に打ち込んでcommand not foundが出なければokです
git --version
npm --version
node --version
preinstall
端末にcommand not foundが出たコマンドを以下のコマンドでインストールしてください
sudo apt install git
sudo apt install npm
コマンド
以下のコマンドを端末で実行することで詳細のような文字列が出力されるはずです
git clone https://github.com/trygfmi/node_executeExportFunction
cd node_executeExportFunction
cd work-directory_execute-export-function
npm init -y
npm install ../install_execute-export-function
cat ../install_execute-export-function/index.js
cat index.js
node index.js
詳細
hello npm command world
hello export function
macos
クリックして詳細を開く
事前確認
以下のコマンドをターミナルに打ち込んでcommand not foundが出なければokです
source ~/bashrc_folder/macports_alias
git --version
npm --version
node --version
※macosはMacPortsパッケージマネージャを使用してコマンドを管理します。もしインストールしていない方は以下のリンクからMacPortsのインストール手順をご覧ください
またコマンドに別名を設定して既存の環境と競合しないでコマンドを呼び出せるようにします。
初めてこのブログを利用する方は、以下の2つの記事を参考に環境構築してください
preinstall
ターミナルでcommand not foundが出たコマンドを以下のコマンドでインストールしてエイリアスを設定してください
sudo port install git
echo 'alias git="/opt/local/bin/git"' >> ~/bashrc_folder/macports_alias
sudo port install npm10
echo 'alias npm="/opt/local/bin/npm"' >> ~/bashrc_folder/macports_alias
echo 'alias node="/opt/local/bin/node"' >> ~/bashrc_folder/macports_alias
コマンド
以下のコマンドをターミナルで実行することで詳細のような文字列が出力されるはずです
source ~/bashrc_folder/macports_alias
git clone https://github.com/trygfmi/node_executeExportFunction
cd node_executeExportFunction
cd work-directory_execute-export-function
npm init -y
npm install ../install_execute-export-function
cat ../install_execute-export-function/index.js
cat index.js
node index.js
詳細
hello npm command world
hello export function
windows
クリックして詳細を開く
事前確認
以下のコマンドをプロンプトに打ち込んでcommand not foundが出なければokです
WSL2
git --version
npm --version
node --version
MSYS2 MINGW64
git --version
npm --version
node --version
※windowsはWSL2とMSYS2 MINGW64で確認しています。可能な限りWSL2をインストールしていただいて、もし設定できなかった場合はMSYS2をインストールすることで実行できますが、所々WSL2でしか実行できないコマンドが出てくるかもしれません。WSL2とMSYS2のインストール方法は下記の記事を参考にしてください
preinstall
プロンプトでcommand not foundが出たコマンドを以下のコマンドでインストールしてください
WSL2
sudo apt install git
sudo apt install npm
MSYS2 MINGW64
pacman --sync git
pacman --sync mingw-w64-x86_64-nodejs
コマンド
以下のコマンドをプロンプトで実行することで詳細のような文字列が出力されるはずです
WSL2
git clone https://github.com/trygfmi/node_executeExportFunction
cd node_executeExportFunction
cd work-directory_execute-export-function
npm init -y
npm install ../install_execute-export-function
cat ../install_execute-export-function/index.js
cat index.js
node index.js
詳細
hello npm command world
hello export function
MSYS2 MINGW64
git clone https://github.com/trygfmi/node_executeExportFunction
cd node_executeExportFunction
cd work-directory_execute-export-function
npm init -y
npm install ../install_execute-export-function
cat ../install_execute-export-function/index.js
cat index.js
node index.js
詳細
hello npm command world
hello export function
後書き
install_executeExportFunctionパッケージのindex.jsでmodule.exportsに格納された関数をworkDirectory_executeExportFunction/index.jsのpkg()で呼び出しています