I created a generic npm package which has my business logic, but I need some google cloud storage information that is in my config files. How can I access this file, if my package is in my node_modules folder? What would be a good solution for that?
this is the structure:
-config
-google_storage_config
-node_modules
-package
-serviceWhichNeedsThatConfig
Based on your folder structure, we will assume your path to the config will be ../../../config/google_storage_config, since node_modules/package/serviceWhichNeedsThatConfig should always be in the root directory.
Now, to access any variables from this config file, simply include the following code in the serviceWhichNeedsThatConfig,
var config = require('../../../config/google_storage_config');
console.log(config.myVariable);
Hi~Have you tried require?
var config = require('../../config/google_storage_config');
Related
is there a way to define multiple npmrc files?
I would like to define a general npmrc with pipeline informations for the CI/CD where the specific access token for gitlab is added as variable. This should be added to git.
In my local folder I would like to define the npmrc file with my private access token.
Is there a way to say 'use the npmrc file in folder xy', and then put this config to a gitignore config?
In a typical nextjs project I find myself with a number of root-level config files:
tsconfig.json
next.config.js
next-seo-config.ts
.eslintrc
etc...
I would like to clean up my root directory and move these files into their own directory. In particular, I would like to create a config directory which would house the above files.
Is this possible in nextjs? If so, how can I do it?
Thanks.
Please, help me understand, how to deal with such issue:
I use vue-cli and I want to build in dev mode some js file and then be able to access it by url like: http://localhost:8080/my-file.js
But by default, I can't do it in such way. As I understand, I have to override devServer option?
You can put the JS files you want to include in a root folder called /public/ and when yarn build runs (or npm build if you're using that) it will output them exactly as they are in public to the dist folder for reference like you're looking for.
Note that the public folder needs to be at the same level as your src folder - not inside the src folder.
Source: https://cli.vuejs.org/guide/html-and-static-assets.html#preload
I'm using roots (http://roots.cx) and I want to include a library from a node_module in my page. I've npm install foo and the library is on disk.
I've tried adding foo to the extensions in app.coffee and restarted the watcher but the path it's rendering is to the node_modules folder which does not resolve from the browser.
extensions: [
js_pipeline(files: 'node_modules/foo/lib/foo.js', 'assets/js/*.coffee'),
css_pipeline(files: 'assets/css/*.styl')
]
and in the page source I get
<script src='node_modules/foo/lib/foo.js'></script>
What is the correct way to include a library from a node module?
Try this instead with the ./ since it's only a file and not a module, like this:
extensions: [
js_pipeline(files: './node_modules/foo/lib/foo.js', 'assets/js/*.coffee'),
css_pipeline(files: 'assets/css/*.styl')
]
Otherwise try to extract or copy the file from the node_modules and put it in a separate folder
In https://github.com/socketio/socket.io/blob/master/test/socket.io.js
The code:
What is the module name to require?
It requires the module from the parent directory - in this case, socket.io
A folder can be used as a module if that folder contains, index.js or package.json files etc.
So in this case it is requiring the socket.io.js file in the above folder.
Also if a package.json and index.js file are in the same folder the package.json will get look up priority.