title: how to configure the __dirname to point to project directory in node?
body: <p>I am adding a sequelize to my node project, it adds the following index.js file as a part of the setup, but when I run the project the __dirname resolves to my C: directory instead of the project root folder 
  C:\workspace\myapp. How do I configure it so that it resolves to my project root directory? </p>
  
  <p>index.js file </p>
  
  <pre><code>'use strict';
  
  const fs = require('fs');
  const path = require('path');
  const Sequelize = require('sequelize');
  const basename = path.basename(__filename);
  const env = process.env.NODE_ENV || 'development';
  const config = require(__dirname + '/../config.json')[env];
  const db = {};
  
  let sequelize;
  if (config.use_env_variable) {
    sequelize = new Sequelize(process.env[config.use_env_variable], config);
  } else {
    sequelize = new Sequelize(config.database, config.username, config.password, config);
  }
  
  fs.readdirSync(__dirname)
    .filter(file =&gt; {
      return (file.indexOf('.') !== 0) &amp;&amp; (file !== basename) &amp;&amp; (file.slice(-3) === '.js');
    })
    .forEach(file =&gt; {
      const model = sequelize['import'](path.join(__dirname, file));
      db[model.name] = model;
    });
  
  Object.keys(db).forEach(modelName =&gt; {
    if (db[modelName].associate) {
      db[modelName].associate(db);
    }
  });
  
  db.sequelize = sequelize;
  db.Sequelize = Sequelize;
  
  module.exports = db;
  </code></pre>
  
  <p>package.json</p>
  
  <pre><code>{
    "name": "my-app-model",
    "version": "0.1.0",
    "private": true,
    "scripts": {
      "dev": "next dev",
      "build": "next build",
      "format": "prettier --write \"src/**/*.{js,jsx,ts,tsx}\"",
      "start": "next start",
      "type-check": "tsc"
    },
    "dependencies": {
      "@material-ui/core": "^4.8.3",
      "@material-ui/lab": "4.0.0-alpha.39",
      "mysql": "^2.18.1",
      "mysql2": "^2.1.0",
      "next": "9.1.7",
      "prettier": "^1.19.1",
      "react": "16.12.0",
      "react-dom": "16.12.0",
      "sequelize": "^5.21.7",
      "sequelize-cli": "^5.5.1"
    },
    "devDependencies": {
      "@types/node": "^13.1.6",
      "@types/react": "^16.9.17",
      "@types/react-dom": "^16.9.4",
      "typescript": "^3.7.4"
    }
  }
  
  </code></pre>