Le Rajk
Le Rajk

Reputation: 15

specific directory path using slash or dot slash (/ or ../) in Nodejs

Ok, this is very simple but I can't seem to figure it out.

I'm currently in (auth -> routes -> users.js) and I want to require a file from a directory in the root (routes -> index.js)

Obviously '...' is not how you do it. The flow of the directories is attached below the code.

//authentication
var express = require('express');
var router = express.Router();
var userdata = require('../controllers/users');
var User = require('../models/users');

//require to lock routes from index.js 
require('.../routes/index.js');

directory

Upvotes: 0

Views: 1242

Answers (2)

Adam LeBlanc
Adam LeBlanc

Reputation: 962

If you use just /foo/bar/bing you'll be using the root of the file system. To go back you use ..

So if you are in Project/auth/routes and want a file in auth, you'd use ../foo, the root of the project, ../../bing.

.. means the parent directory and . means the current directory. You can chain them together all the way to the file system root.

Upvotes: 0

Brett Beatty
Brett Beatty

Reputation: 5973

.. is up one level, so you need to combine two of those with a slash like so: ../../routes/index.js

Upvotes: 1

Related Questions