Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nodemon .\src\server.js first second vs nodemon first second help... #1758

Closed
softwarenerd opened this issue Sep 3, 2020 · 2 comments · Fixed by #1773, elirehema/pcapi#23, elirehema/real-estate#34 or vdonoladev/CasaCriativa#8 · May be fixed by TheDogenode/torrent-aio-bot#4
Labels
bug confirmed bug windows

Comments

@softwarenerd
Copy link

softwarenerd commented Sep 3, 2020

  • nodemon -v: 2.0.4
  • node -v: v14.8.0
  • OS: Windows 10, Powershell, macOS

I have a quick question that has perplexed me since I started using nodemon. Here's the relevant section from my package.json:

  "main": "./src/server.js",
  "scripts": {
    "start": "node src/server.js"
  }

If I execute nodemon .\src\server.js first second then console.log(process.argv) looks like:

[
  'C:\\Program Files\\nodejs\\node.exe',
  'C:\\Users\\brian\\Code\\server\\src\\server.js',
  'first',
  'second'
]

However, if I want to take advantage of nodemon's ability to automatically run the file associated with the main property of my package.json file, and I execute nodemon first second, then console.log(process.argv) looks like:

[
  'C:\\Program Files\\nodejs\\node.exe',
  'C:\\Users\\brian\\Code\\server\\src\\server.js',
  'second',
  './src/server.js'
]

The first argument gets eaten.

Expected behaviour

I expect nodemon to determine that first isn't a Node application, so it should load the file associated with the main property of my package.json file, and then pass my first and second arguments to it. I expect console.log(process.argv) to look like:

[
  'C:\\Program Files\\nodejs\\node.exe',
  'C:\\Users\\brian\\Code\\server\\src\\server.js',
  'first',
  'second'
]

Actual behaviour

My arguments are jumbled up. My second argument appears as the first argument, my first argument doesn't appear at all, and my file associated with the main property of my package.json file appears as the second argument.

[
  'C:\\Program Files\\nodejs\\node.exe',
  'C:\\Users\\brian\\Code\\server\\src\\server.js',
  'second',
  './src/server.js'
]

Steps to reproduce

Show above.

nodemon has been around forever and is wonderful, so I assume that I'm being an idiot and there's just something I don't understand. I want the ease of being able to enter commands like:

nodemon dev

and:

nodemon dev-test

so I can easily switch environments. I don't want to have to type in my main .\src\server.js every time like this:

nodemon .\src\server.js first second

Thanks!

@softwarenerd softwarenerd changed the title nodemon nodemon .\src\server.js first second vs nodemon first second nodemon .\src\server.js first second vs nodemon first second help... Sep 3, 2020
@stale
Copy link

stale bot commented Sep 20, 2020

This issue has been automatically marked as idle and stale because it hasn't had any recent activity. It will be automtically closed if no further activity occurs. If you think this is wrong, or the problem still persists, just pop a reply in the comments and @remy will (try!) to follow up.
Thank you for contributing <3

@stale stale bot added the stale no activity for 2 weeks label Sep 20, 2020
@remy remy added the windows label Oct 3, 2020
@stale stale bot removed the stale no activity for 2 weeks label Oct 3, 2020
@remy remy added bug confirmed bug and removed bug confirmed bug labels Oct 3, 2020
@remy
Copy link
Owner

remy commented Oct 3, 2020

This is slightly buggy, but not the way you think.

The first second should be passed to node (or whatever the exec is), and then the user script is passed.

So we should see:

node first second ./server.js

The question is, where is first going?

But to solve your problem, you want to pass to your script, so you tell nodemon to stop slurping:

nodemon -- first second

However, that doesn't quite work, so I'm filing as a bug.

@remy remy added the bug confirmed bug label Oct 3, 2020
remy added a commit that referenced this issue Oct 4, 2020
Fixes #1758

The combination of using a package.main (which sets the script
position to index zero) and using the -- stop slurp meant that
the arguments had the script appended to the end instead of
prepended to the start. The net result meant that when the script
was forked, it would drop the first user arg.

See diff for details of the fix - a simple check against null.
@remy remy closed this as completed in #1773 Oct 4, 2020
remy added a commit that referenced this issue Oct 4, 2020
* fix: package.main with -- arguments

Fixes #1758

The combination of using a package.main (which sets the script
position to index zero) and using the -- stop slurp meant that
the arguments had the script appended to the end instead of
prepended to the start. The net result meant that when the script
was forked, it would drop the first user arg.

See diff for details of the fix - a simple check against null.

* fix: protect against missing opts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment