0

in a node tutorial, the author use this var require = require('./something');

I wonder why it's not require('../something'), which goes up one level and find something

2

3 Answers 3

3

. represent the current working directory

.. represent the parent directory of the current working directory.

So, if we use require('./something'), that means we want to find something in the current directory.

Sign up to request clarification or add additional context in comments.

Comments

2

In a directory tree such as

root
  dir
     file1
     file2
  dir2
     file1
     file2

If you are in root/dir . refers to root/dir so ./file1 refers to /root/dir/file1. .. refers to root so ../file1 doesn't exist (root/file1)

Comments

-1

You can do a relative redirect:

'../' == one level up
'/path' == relative to domain

Directory Separator = /
Current Directory = .
Parent Directory = ..
Home Directory = ~

1 Comment

I think, avoid using \ character. It may also work but its not recommended as it can act as escape character. Escape Characters eg: C:\file may be interpreted as C:ile

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.