I have been writing Node.js apps for quite some time now, and I have been seldom paying any attention to the use of forward slash vs backward slash when loading files using Node.js on Windows.
Now, after using both interchangeably without a problem, I’m starting to wonder, is there a significant difference between the two?
Up until now, the only difference that I have noticed is that JavaScript’s string literal (just like C and C++), requires that every backward slash be preceded by another backward slash. (In fact this is why I have been reluctant to use the backward slash, recently — even for Node.js on Windows –, because I fear forgetting that extra slash.)
Just like what Raynos said in the comments, I should use the forward slash always, even on Windows.
Update
The above answer is really, really outdated. Always use
path.joinwhen constructing file paths from scratch.Example: