Skip to content

Instantly share code, notes, and snippets.

@janniks
Created April 22, 2020 09:37
Show Gist options
  • Save janniks/8507925554cccf48df12c889b313accf to your computer and use it in GitHub Desktop.
Save janniks/8507925554cccf48df12c889b313accf to your computer and use it in GitHub Desktop.
03 - A Better Way to Import Local Node.js Modules - An Article
const projectRoot = require('app-root-path');
const random = require(projectRoot + '/somewhere/deep/and/random.js');
// OR using .require
const requireLocal = require('app-root-path').require
const random = requireLocal('somewhere/deep/and/random');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment