mystuff - easier local require
This module makes it easier to organize and require your local modules. It also gives you the ability to set global variables that you can use in all of your projects.
Installation
npm install mystuff
When you require mystuff
for the first time it creates a folder named own_modules
in your users home directory.
In this folder you can store your own modules.
Own Modules
You can create your modules in two ways: as a single JavaScript file or as a directory.
File
- Create a JavaScript file e.g.
example.js
in theown_modules
folder. - Write your Code in the file and set the
module.exports
property. - Now you can require this file in all of your projects.
const mystuff = require('mystuff');
var example = mystuff('example');
//or
var example = mystuff('example.js');
Directory
- Create a directory e.g.
anotherExample
in theown_modules
folder. - Add a JavaScript file called
anotherExample.js
ormain.js
in the new directory. They are used as entry-point. - Write your code in the JavaScript file and set the
module.exports
property. - Now you can require this module in all of your projects.
const mystuff = require('mystuff');
const anotherExample = mystuff('anotherExample');
Tip: The main.js
file ist the prefered entry-point.
cd(path)
Change the directory where your own_modules
folder is located in.
The change affects the whole node app.