Skip to main content
Stack Overflow
  1. About
  2. For Teams

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

How do I pass command line arguments to a Node.js program and receive them?

I have a web server written in Node.js and I would like to launch with a specific folder. I'm not sure how to access arguments in JavaScript. I'm running node like this:

$ node server.js folder

here server.js is my server code. Node.js help says this is possible:

$ node -h
Usage: node [options] script.js [arguments]

How would I access those arguments in JavaScript? Somehow I was not able to find this information on the web.

Answer*

Draft saved
Draft discarded
Cancel
1
  • like it a lot 🙏 just in case a nice addition might be to lowercase args e.g. new Set(process.argv.slice(2).map((a) => a.toLowerCase())); Commented Oct 6, 2023 at 17:18

lang-js

AltStyle によって変換されたページ (->オリジナル) /