Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5947493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:58:18+00:00 2026-05-22T16:58:18+00:00

Came across this situation recently – I have an environment variable for a directory

  • 0

Came across this situation recently – I have an environment variable for a directory path like so:

var fooDir = process.env.FOO_DIR;

and I want to make sure this directory exists with a synchronous mkdir (at some point later):

fs.mkdirSync(fooDir, mode);

however if the user has supplied the environment variable via a realtive ~/ path node cannot resolve it

export FOO_DIR='~/foodir'

is there a way in node to resolve this without invoking a child process exec call to the actual shell? currently my solution is to do a replace myself like so:

fooDir = fooDir.replace(/^~\//, process.env.HOME + '/');

just curious if someone has a better solution.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T16:58:19+00:00Added an answer on May 22, 2026 at 4:58 pm

    You have it right: ~ is expanded by the shell, not the OS, just like *. None of the C file functions that node.js wraps handle ~ either, and if you want this you have to do the replacement yourself, just as you’ve shown. I’ve done this myself in C when supporting config files that allow relative file paths.

    However, you should probably handle the case where HOME isn’t defined; I believe this happens with non-interaction logins with bash, for example, and the user could always choose to unset it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I came across this recently, up until now I have been happily overriding the
I came across with this situation. I have one already developed Application in 2.0,
I haven't actually came across this situation yet but i will probably have a
I'm practising on threading and came across this problem. The situation is like this:
I came across this class while reading a C# book and have some questions.
I recently came across the situation where I wanted a set of classes to
working with a team of more traditional developers we came across this situation: We
I came across this very odd situation, and i thought i would throw it
I have came across many situation where I needed to pass value to an
I am fairly new to SSIS. I came across a situation where i have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.