Any way to force strict mode in node?

According to Lloyd you can now place

"use strict";

at the top of your file in node >= 0.10.7, but if you want your whole app to run in strict (including external modules) you can do this

node --use_strict


In node 0.10.7 you can enforce strict mode at file level by placing "use strict"; at the top of your file. Finally!


Just use "use strict"; at the top of applicable files. I know it's tempting to try to cut out boilerplate, but it simply can not be done in Javascript. The node flag which shall not be named[1]

  • is undocumented, and unsupported by Node itself.
  • has faced proposals to remove it.
  • is node-specific and is not supported in any other JavaScript engine.
  • is unstandardized.
  • it is not the same as "use strict"; because it is a compiler global, and like all globals you're potentially adversely impacting someone else's code.
  • everything is subject to bugs. strict mode and sloppy-mode may be subject to different bugs. that is to say, some strict mode bugs are unique to strict mode

Some other programmers may think this is similar to -wALL or the like, it's not. This is standardized functionality that you're enabling in an ad-hoc fashion (breaking the standard) and changing everyone's compiler semantics.

Footnotes

  1. The node flag is --use_strict. Don't use it.

Tags:

Node.Js