What does -c flag do in NodeJS? - javascript

In my MacOS terminal, I typed node -c (the -c flag was by mistake). But it worked exactly like node and I can't see any difference.
I searched online but I am unable to find any reference to the -c flag.
Does anyone know what it does??

The -c flag usually checks the syntax without having your node.js script executed.
When you type, node --help you will see the usage listed like this,
-c, --check syntax check script without executing
Hope this helps!

If you type node --help you can get all available options.
-c, --check syntax check script without executing

According to the documentation:
-c, --check
Check the script's syntax without executing it. Exits with an error code if script is invalid.

Related

$ npm install eslint -g = -bash: $: command not found

I am trying to globally install eslint on my mac to use in vs code and it is returning the command not found. does anybody have any idea on how to fix this?
What specifically is not "found"? Is it NPM? If so, check your PATH variable.
Since you are using a Mac, it should be here:
/usr/local/bin/npm
Also, this is a very generic and common question, please do some more research before posting here.
Edit: As per my comment below.
Are you passing $: at the start of that command? In most documentation, this refers to the shell command prompt and should not be included in the command.

JavaScript: How to use WebStorm debugger with ava

This is not question, just answer:
Create run/debug configuration, type Node.js
Select your node interpreter
As node parameter insert your ava bin and parameter --verbose
For me it's: ./node_modules/.bin/ava --verbose
Select your working directory
Done, now you can debug
The magic is in --verbose, I have no idea why it works that way, but it does.
I have no idea why/how it works for you - configuration is definitely wrong.
With your configuration, --inspect-brk is passed to ava, not to Node.js, and thus treated as your application argument. You should have specified node_modules/.bin/ava as JavaScript file: in your Run configuration instead of specifying it as a Node parameter, to make sure that Node debug arguments are passed before the application main file. --verbose can be passed as application parameter.
See also https://github.com/avajs/ava/blob/master/docs/recipes/debugging-with-webstorm.md
Create a new node test runner with following configuration:
Node interpreter: whatever version of node that you are using that is compatible with your ava version
Working directory: ~/Documents/Work/projectRootDir
Javascript file: node_modules/ava/cli.js
Application parameters: -v outdir/testFile e.g. /dist/test/controllers/test.js
There you go, now you can run and debug AVA with the best javascript IDE instead of console logging!
I'm quite sure that vscode config will be quite similar

"CALL "C:\Program Files\nodejs\\node.exe" Error

I have been trying insall node js and install browser sync
C:\Users\Aly>npm install -g browser-sync
'CALL "C:\Program Files (x86)\nodejs\\node.exe" "C:\Program Files `(x86)\nodejs\\`
node_modules\npm\bin\npm-cli.js" prefix -g' is not recognized as an internal or external command,operable program or batch file.
Even if i want to know my node js version , the same error appear and then the version shown after that
C:\Users\Aly>npm --version
'CALL "C:\Program Files (x86)\nodejs\\node.exe" "C:\Program Files `(x86)\nodejs\\`
node_modules\npm\bin\npm-cli.js" prefix -g' is not recognized as an internal or external command,operable program or batch file.
3.10.9
Windows 10
Thanks So Much In Advance
I just spend way to long with this issue. I'm not sure how it got set, perhaps during an install, but I changed a System Variable:
Name: ComSpec
Value: %SystemRoot%\system32\cmd.exe;prefix=C:\Program Files (x86)\nodejs\node.exe
To this:
Name: ComSpec
Value: %SystemRoot%\system32\cmd.exe
And restarted my system and the issue was gone.
Good catch blur0224.
I also spent way too long on this issue reinstalling node in various ways and investigating administrator privileges for the %appdata%/roaming/npm -folder.
Your solution worked for me also. The ComSpec variable contained old trash (referring to uninstalled programs) which somehow interfered when calling npm.
Side note 1: What was REALLY confusing was that calling npm worked for many npm package retrievals, but not all. Error code in the failed cases would for me contain keywords such as code ELIFECYCLE and errno ENOENT.
Side note 2: I also received warning 1909 could not create shortcut node.js command prompt.lnk when installing node - perhaps implying that an environmental variable was not properly installed.
Anyone seeing the symptoms from the two previous paragraphs could try the answer from blur0224. I hope this helps people searching for these keywords.
Firstly, check using GitBash whether the npm -v command executes successfully.
If NPM is working in GitBash, then it is not a path problem (your path reference is OK).
Go to Environment Variables > System Variables and check if ComSpec: %SystemRoot%\system32\cmd.exe is correctly configured, or not.
In some cases, if you have a trailing slash, it will not work. (eg: ComSpec : %SystemRoot%\system32\cmd.exe\) If so, simple remove the trailing slash.
Otherwise, check where cmd.exe is located and use that path as the ComSpec value.
Usually, it resides at c://Windows/System32/cmd.exe.

building modernizr on the windows command line

So I followed the docs here:
https://github.com/modernizr/modernizr
1) cloned the repo using npm.
2) ran npm install inside modernizr to install its dependencies.
3) tried to run ./bin/modernizr -c lib/config-all.json
I am getting an error:
'.' is not recognized as an internal or external command
I am assuming that this has to do with the windows command line not understanding that I am trying to execute the file at that location. How can I do step 3 on cmd?
Thanks in advance.
Here we go. You need to run the modernizr bin from within node.
node .\bin\modernizr -c .\lib\config-all.json
Run the instructions in PowerShell. It does a better job of support *nix-style syntax and commands than the Command Prompt.
Use Git Bash (part of Git for Windows) or (iof you feel like going in the front door) Minimalist GNU For Windows (http://www.mingw.org/) It works fine.

Does Mocha ignore --harmony option in mocha.opts?

In my test directory, I have a file mocha.opts containing the following:
--harmony
--recursive
--growl
--reporter spec
--require should
When I run mocha, I get the following error:
/project/server/utilities/encryption.js:3
const
^^^^^
SyntaxError: Use of const in strict mode.
This is, of course, because my use of const requires ES6 Harmony. When I run mocha --harmony, my tests execute just fine. And the other entries in my mocha.opts file work as expected.
Does the mocha.opts file ignore the --harmony argument for some reason? Or am I doing it wrong? The Mocha docs don't elaborate and I haven't been able to find the answer here or anywhere else.
The asker asks:
When I run mocha --harmony, my tests execute just fine. [...]
Does the mocha.opts file ignore the --harmony argument for some reason?
Yes, mocha.opts ignores the --harmony argument. The --harmony option is not a Mocha option but a Node.js option. This is an option that must be passed to Node.js before it starts executing. However, mocha.opts is read after Node.js has started and so even if Mocha was able to understand the option, it would not be able to do anything about it.
But why does it work on the command line? Shouldn't it be the case that when I run mocha --harmony, Mocha has to first start before parsing the --harmony option? No, because mocha is script that starts the "real" Mocha. The shell script detects --harmony and makes sure it is passed to Node.js when it starts the "real" Mocha.
It's not support as something you can include in mocha.opts. You much add in to the command line when you call mocha. See this.

Categories