Skip to content

Unable to disable REPL history on Windows #25661

Description

@ralish
  • Version: 10.15.0
  • Platform: Windows 10 x64 (1809)
  • Subsystem: REPL (lib/internal/repl.js)

Per the REPL documentation the history file path can be changed by setting the NODE_REPL_HISTORY environment variable to a valid path or disabled by setting it to the empty string.

On Windows platforms an empty environment variable is difficult to set. From my own testing:

  • A variable cannot be saved with a blank value via the System Properties UI (sysdm.cpl).
  • Setting the value to '' or "" will set it to a literal two single quotes or double quotes when using the System Properties UI.
  • Setting the value to '' will set it to a literal two single quotes when using the setx Command Prompt utility.
  • The .NET Environment.SetEnvironmentVariable method notes that an empty variable value will result in the variable being deleted if it exists or a no-op if it doesn't.

I've found that a blank variable can be set using setx with two double quotes: setx NODE_REPL_HISTORY "". I haven't tried calling the underlying Win32 SetEnvironmentVariable function directly but given the behaviour of setx it presumably would work.

It seems clear to me that setting blank environment variables is discouraged and the support for doing so is patchy at best. This being the case, it would be desirable to support an alternate value that's legal on Windows to indicate that the REPL history should not be saved. One possible option would be recognising the value '' (i.e. two single quotes) which in my view is the most intuitive setting, but there's of course other options.

Thoughts?

Activity

  1. ralish commented on Jan 23, 2019

    @ralish
    ContributorAuthor

    I spoke too soon, the setx NODE_REPL_HISTORY "" method doesn't work either. It does create a blank variable, and I can see it gets added to the Registry, but it's not actually visible in any launched process. I've confirmed this using console.log(process.env); in Node and from viewing the process environment using Process Explorer. Presumably the Win32 loader removes blank variables when creating a process.

    The blank variable can be seen in the System Properties UI, presumably because it enumerates them from the Registry rather than its process environment, but it can only be deleted or a value set.

    So as it stands it seems disabling the REPL history is not possible on Windows until an alternate non-blank value is recognised for the NODE_REPL_HISTORY environment variable.

  2. changed the title [-]Add alternate recognised value to disable REPL history on Windows[/-] [+]Unable to disable REPL history on Windows[/+] on Jan 23, 2019
  3. added
    replIssues and PRs related to the REPL subsystem.
    windowsIssues and PRs related to the Windows platform.
    on Jan 23, 2019
  4. bzoz commented on Jan 23, 2019

    @bzoz
    Contributor

    Try set NODE_REPL_HISTORY=

  5. BridgeAR commented on Jan 23, 2019

    @BridgeAR
    Member

    @ralish setting the environment variable to an empty string or a string that contains only whitespace should work just fine (as documented). I guess the latter should work even if Windows does not recognize empty strings.

  6. bzoz commented on Jan 23, 2019

    @bzoz
    Contributor

    Sigh, my bad, missed a space: "set NODE_REPL_HISTORY= " (with a space after '='). That will disable repl.

  7. ralish commented on Jan 23, 2019

    @ralish
    ContributorAuthor

    @bzoz: You're right, this does work, thanks!
    @BridgeAR: Yep, the fact whitespace is trimmed is the key.

    Can I suggest at least a documentation update to make it a bit more explicit that on Windows one or more space characters should be used? Right now it's implied on closer reading with the whitespace trimming, but making it concrete would I think be helpful as the empty string is not valid on Windows.

  8. BridgeAR commented on Jan 23, 2019

    @BridgeAR
    Member

    @ralish please feel encouraged to open a pull request to improve the wording :-)

  9. ralish commented on Jan 23, 2019

    @ralish
    ContributorAuthor

    @BridgeAR: Sure, done in PR #25672.

  10. added
    docIssues and PRs related to Node.js documentation.
    and removed
    questionIssues asking questions about Node.js.
    on Jan 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    docIssues and PRs related to Node.js documentation.replIssues and PRs related to the REPL subsystem.windowsIssues and PRs related to the Windows platform.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions