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

How to configure nodemon.json to run node with arguments which contains space #1823

Closed
chucklu opened this issue Jan 6, 2021 · 12 comments
Closed

Comments

@chucklu
Copy link

chucklu commented Jan 6, 2021

  • nodemon -v: 2.0.6
  • node -v: v12.18.0
  • Operating system/terminal environment: win10/cmd.exe
  • Command you ran:

Configuration in nodemon.json

  "events": {
	"exit": "node printdate.js \"cleanly exited\""
  }

Expected behaviour

I test the node command node printdate.js "cleanly exited" successfully with cmd.exe, and the output is

cleanly exited at 2021-01-06 17:32:42 408ms UTC+8

The parameters were

[
  'node.exe',
  'printdate.js',
  'cleanly exited'
]

Actual behaviour

'display at 2021-01-06 17:32:42 408ms UTC+8
The parameter generated by nodemon were

[
  'C:\\Program Files\\nodejs\\node.exe',
  'C:\\workspace\\Edenred\\UK\\Connect_Incentive_Frontend\\vueSrc\\printdate.js',
  '"cleanly',
  'exited"'
]

What happened here? why the last parameter was divided into two parts?

Steps to reproduce

The content of printdate.js is as following

//console.log(process.argv);
var myArgs = process.argv.slice(2);
//console.log('myArgs: ', myArgs);

const dateTime = require('date-time');
var currentTime = dateTime({local: true, showTimeZone: true, showMilliseconds: true});
console.log(`${myArgs[0]} at ${currentTime}`)
@remy remy added the windows label Jan 6, 2021
@remy
Copy link
Owner

remy commented Jan 6, 2021

This seems to be windows specific (if anyone wants to have a shot) - also it's not clear from original post if this is spaces in nodemon args or nodemon events.

Running on mac/linux:

nodemon -- "testing"                                                                                                                       
[nodemon] master: 2967726673496ae6cf35904cb4e83013c6e2ccd3
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node index.js testing`
testing at 2021-01-06T10:21:04.104Z
[nodemon] clean exit - waiting for changes before restart
cleanly exited at 2021-01-06T10:21:04.166Z

index.js:

//console.log(process.argv);
var myArgs = process.argv.slice(2);
//console.log('myArgs: ', myArgs);

var currentTime = new Date().toJSON()
console.log(`${myArgs[0]} at ${currentTime}`)

nodemon.json:

{
  "events": {
    "exit": "node index.js \"cleanly exited\""
  }
}

@chucklu
Copy link
Author

chucklu commented Jan 6, 2021

@remy But I can execute node printdate.js "cleanly exited" through cmd.exe on Windows correctly.

@remy
Copy link
Owner

remy commented Jan 6, 2021

@chucklu remember you're also going through npm

@chucklu
Copy link
Author

chucklu commented Jan 7, 2021

@remy Do you mean this is a bug of npm?

@caesay
Copy link

caesay commented Feb 4, 2021

Make sure you are not mix-matching single and double quotes, and you don't forget to escape them:

  "scripts": {
    "start": "nodemon printdate.js \"cleanly exited\""
  },

Ran with npm start works just fine on my Windows system, however by replacing the double quotes with single quotes I can re-produce what you have experienced.

From your posted config:

"events": {
"exit": "node printdate.js "cleanly exited""
}

It appears you may have forgotten to escape the double quotes surrounding cleanly exited

@chucklu
Copy link
Author

chucklu commented Feb 5, 2021

@caesay Thanks, I will check it. I did not notice that @remy had already modified the exit script in previous comment.

Currently I encounter another issue, which blocked me to confirm the escape double quotes

[nodemon] clean exit - waiting for changes before restart
internal/modules/cjs/loader.js:969
throw err;
^

Error: Cannot find module 'C:\workspace\vueSrc\index.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:966:15)
at Function.Module._load (internal/modules/cjs/loader.js:842:27)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
at internal/main/run_main_module.js:17:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}

@chucklu chucklu closed this as completed Feb 5, 2021
@chucklu
Copy link
Author

chucklu commented Mar 25, 2021

@caesay Still did not work, use the same script as you provided

"exit": "node printdate.js \"cleanly exited\""

What I got is as following, still break at the space

"cleanly at 2021-03-25 10:51:11 121ms UTC+8

@chucklu chucklu reopened this Mar 25, 2021
@github-actions
Copy link

github-actions bot commented Jul 9, 2021

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

@github-actions github-actions bot added the stale no activity for 2 weeks label Jul 9, 2021
@chucklu
Copy link
Author

chucklu commented Jul 9, 2021

@remy @caesay

@github-actions github-actions bot removed the stale no activity for 2 weeks label Jul 9, 2021
@remy remy changed the title How to cofigure nodemon.json to run node with arguments which contains space How to configure nodemon.json to run node with arguments which contains space Jul 9, 2021
@remy remy closed this as completed in 0823f18 Jul 10, 2021
@remy
Copy link
Owner

remy commented Jul 10, 2021

The commit that closed this issue (early) adds the fix for windows for this particular issue. The release should auto tag this issue, but if not it'll be in 2.0.12.

@github-actions
Copy link

🎉 This issue has been resolved in version 2.0.12 🎉

The release is available on:

Your semantic-release bot 📦🚀

@chucklu
Copy link
Author

chucklu commented Jul 12, 2021

@remy Thanks for you fix, it works now with the following configuration section in nodemon.config

"exit": "node printdate.js "cleanly exited""

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants