Ngọc Hy
Ngọc Hy

Reputation: 300

npm: import from outside the src folder

So I have this NodeJS project with the following folder tree

+ node-folder
   + react-app-folder
   + (other folders...)
   + config
       + default.json

What I am trying to do is import that default.json file to any file in that react-app-folder.

The node-folder and react-app-folder have their own package.json file.

Is there any way of doing this?

Thank you all very much.

EDIT: For more details about the node-folder . It is a NodeJS app server whose package.json has a script using concurrently to run both the nodejs-app on port 3000 and react-app on port 3001

Upvotes: 3

Views: 5856

Answers (2)

Manoj Bhat
Manoj Bhat

Reputation: 64

If I understood your question correctly, I believe that you are using create-react-app. The ModuleScopePlugin enforces a restriction that prevents you from importing files outside src folder. Removing this from your webpack configuration will allow you to import files out of react app scope. Please check this similar question.

Upvotes: 4

Narro
Narro

Reputation: 440

i think require is ok, isn't it?

commonjs

// node-folder/config/default.json
exports.PORT = 8080;
// node-folder/server/app.js
var config = require('../config/config');

console.log(config.PORT);

Upvotes: -2

Related Questions