Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is "~/" not recognized from node.js?

I wanted to set a path to my user folder with "~/". Why is this not valid in javascript?

like image 860
pawi Avatar asked Feb 01 '26 02:02

pawi


2 Answers

It has nothing to do with JavaScript. Node's file operations just don't expand ~ for you. It's not something that the file system automatically handles, it's something various programs (like your terminal, file manager, etc.) handle. You can get the home directory via os.homedir().

like image 51
T.J. Crowder Avatar answered Feb 03 '26 15:02

T.J. Crowder


Tilde expansion is a bash feature that does not necessarily apply dependent on where the software is deployed. It also opens up questions about supporting other operators.

See https://github.com/nodejs/node/issues/684

like image 33
cmbuckley Avatar answered Feb 03 '26 16:02

cmbuckley