node-use-requiredeprecated

node use require absolute path

Usage no npm install needed!

<script type="module">
  import nodeUseRequire from 'https://cdn.skypack.dev/node-use-require';
</script>

README

node-use-require

Node require absolute path. Simply Easy Smaller < 1Kb

Problem

When the directory structure of your Node.js application (not library!) has some depth, you end up with a lot of annoying relative paths in your require calls like:

const mysql = require('../../../../db/mysql')

Those suck for maintenance and they're ugly. link

Install

npm install node-use-require --save

How to use

global.use = require('node-use-require')

or

const use = require('node-use-require')

Example

-root
--app
----db
------mysql.js
------mongoose.js
----routes
------group
---------subGroup
------------router.js
--server.js
--node_module
--package.json

When router.js require mysql.js relative path

const mysql = require('../../../../db/mysql')

When router.js require mysql.js absolute path

const use = require('node-use-require')
const mysql = use('app/db/mysql')

Authors

  • Nonthachai Korninai - Github

License

This project is licensed under the MIT License