Repository navigation
Cannot disable warnings when node is launched via a shell script. #10802
Description
Activity
- changed the title
[-]Cannot disable warnings when scripts are launched from the shell.[/-][+]Cannot disable warnings when node is launched via a shell script.[/+]on Jan 14, 2017 - addedfeature requestIssues requesting new Node.js features.Issues requesting new Node.js features.processIssues and PRs related to the process subsystem.Issues and PRs related to the process subsystem.
on Jan 14, 2017 - added a commit that references this issue
on Jan 19, 2017 - added 2 commits that reference this issue
on Jan 25, 2017 - added 2 commits that reference this issue
on May 16, 2017 - added a commit that references this issue
on Jul 19, 2017 What's the solution?
When I try putting this at the top of my file:
#!/usr/bin/env NODE_NO_WARNINGS=1 nodeI just get:
/usr/bin/env: ‘/path/to/my/script’: Text file busy- Reacted by Ben Mark and Lajos MészárosReacted by Brandon Davis, Ameer Hamoodi, Kevin Boshold, Hunter Kohler, Darin Hensley and Ross Williams
@Doragd Huh? How would that work... the file contains JavaScript, it'll syntax error on
export NODE_NO_WARNINGS=1Reacted by hexrcs, Viraj Shelke, Brandon Davis and Ross Williams8 remaining items
@jasnell one issue I just noticed is that that can't be set from within the program when it has already launched.
Reacted by Busticated@benjamingr, are you able to put it in the shebang? This worked for me:
#!/usr/bin/env NODE_OPTIONS=--no-warnings nodeReacted by Florian Cargoët, yairhaimo and i7eoReacted by Fabiano Taioli and Alex LeeThis also worked for me:
process.env.NODE_NO_WARNINGS = 1;
Reacted by Fedor@squallstar doesn't work for me.
Which node version are you testing on? I'm testing
fs.promiseson node 10.16.0. The module doesn't emit a warning in v12.13.0 though because I believe it's no longer experimental.@hexrcs the above works for me on Node 12. I have right before a
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';and this doesn't trigger a warning (while it does whenNODE_NO_WARNINGSis not defined).Is this documented anywhere? I couldn't find anything about this env variable but it would certainly be great if we finally get this feature. :)
@hexrcs https://nodejs.org/api/cli.html#cli_node_no_warnings_1 (or search for
NODE_NO_WARNINGSon that page, the setting was added on Node 6).Weird, because setting it to either a string
"1"or number1doesn't work on node v10 on my system (MacOS 10.14.6). (I was requiring thefs.promisesmodule.)Just tested on node v12.13.0 using the example below, also doesn't seem to work. :(
$ node > process.env.NODE_NO_WARNINGS = 1 // 1 > process.emitWarning('something strange happened') // (node:18941) Warning: something strange happened > process.env.NODE_NO_WARNINGS = "1" // "1" > process.emitWarning('something strange happened') // (node:18941) Warning: something strange happenedIf the node interpreter is spawned with
node --no-warnings, thenprocess.emitWarningwill do nothing.@hexrcs I just tested on Node v12.13.0 and I am using Mac OS 10.15.2 (19C57), works great from here.
Reacted by hexrcs@hexrcs something which you can try is to spawn a child process after the env variable has been updated. I remember doing that on previous versions of node when using commander to create a node-based CLI tool.
@squallstar Thanks for the tip :) I've been doing similar things:
OK, I just upgraded node to v12.14.1, also doesn't work... Way too weird.
Anyway, I'll keep using the child process approach for now.
I raised this same issue here (oops): #32876 and @sam-github kindly took the time to explain there's a solution using
process.removeAllListeners('warning').Reacted by Vladimir Panchenko, Radek Stepan, Kadar Claudiu, Peter Evans, grkblood13, Renato Oliveira, 宇果, Jeff Hall, Gyubong Lee, Ilia Choly and 14 moreReacted by Zaghar, Leo Vo, Ilia Choly, brandon flowers, Bryce Carr, Jānis Blaus, Shivam, Pkmmte Xeleon and Jyotirmoy BandyopadhayayaReacted by Peter Evans, Zaghar, sandboxcmd, Ilia Choly, Bryce Carr, Brian McCann, Jānis Blaus, Kees C. Bakker, Shivam, Kyle Pittman and 3 more- added a commit that references this issue
on May 4, 2024 - added a commit that references this issue
on Jun 19, 2026

As an end-user, I don't want to ever see warnings or deprecations. However, when node is invoked from a shell script via a shebang, there is no opportunity to pass the
--no-warningsoption to the process.Is there an environment variable that can be set to toggle this option? If not, please add support for something like
NODE_NO_WARNINGS=1.