I have a directory that contains two folder : my server app (NodeJS
) and my client app (ReactJS
).
My directory structure looks like this :
root/
|- client/
|- package.json
|- src/
|- ...
|- server/
|- package.json
|- src/
|- ...
How can I add a common
folder at the root of my directory to share enums and utils with both my server and my client ?
Thanks!
You have multiple solutions:
create a folder common
under root and just require the files you need from your files. But you could end up with "long" require such as require("../../../../../common/file")
use module-alias to avoid that problem: https://github.com/ilearnio/module-alias
you could make common
a local module (using file:
) and install it in package.json
https://docs.npmjs.com/files/package.json#local-paths
{
"name": "common",
"dependencies": {
"common": "file:../common"
}
}
Then you can just require what you need easily
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With