Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
node helloworld.js alex
console.log() アレックスにしたい。「alex」を引数としてコードに渡すにはどうすればよいですか?
pythonでは、それはsys.argv[1]
sys.argv[1]
process.argvnode.jsを使用してコマンドライン引数にアクセスできます。
process.argv
配列にはノードコマンドとアプリケーションファイルも含まれているため、最初のカスタムコマンドライン引数のインデックスは2になります。
process.argv[2] === 'alex'; // true
http://nodejs.org/api/process.html#process_process_argv