1

I have created an npm package that is supposed to create a directory in the project's root directory (using postinstall) when it is installed via npm.

Currently I have a script (createConfigDir.js) that is supposed to create the config directory:

const path = require('path');
const mkdirp = require('mkdirp');
const projectPath = path.join(process.cwd(), '../../config');

mkdirp.sync(projectPath)

then in the package.json under script I do:

scripts{
    "postinstall":"node ./scripts/createConfigDir.js"
}

When the package gets installed the config folder gets created but outside the project's root directory. If I change the path from const projectPath = path.join(process.cwd(), '../../config'); to const projectPath = path.join(process.cwd(), '../config'); the folder gets created inside my package. How can I create the directory inside the project's root directory?

What am i doing wrong? Is this possible in node?

coderdark
  • 1,481
  • 14
  • 30

0 Answers0