Recently I started working on a pretty old application where API endpoint URL differs on each system.
Right now, my package.json looks like this:
"start": "cross-env API_ENDPOINT=http://localhost:5000/api/v1 react-scripts start"
The problem is, this value is currently static so when I deploy the code into Heroku, it tries to connect my localhost. Instead, I'm looking to do something like this:
"start": "cross-env API_ENDPOINT={thisShouldBeDynamic} api/v1 react-scripts start"
Is there any way to do it?
Ps. react-app-scripts version is ^0.4.0 so I cannot rely on .env and believe me, you wouldn't want to update it.
JSON format doesn't support templating itself, so you need to create a script which will opens config.json, update it and save back to same file.
You can start from https://www.npmjs.com/package/config-template and create your own template filler which retrieve env variables you need and add them to config file, then same a file.
You can alter your installation before it starts up with the postinstall NPM hook. https://devcenter.heroku.com/articles/nodejs-support#customizing-the-build-process
For instance:
"scripts": {
"postinstall": "node ./ops/heroku-build.js"
}
And then in that script, simply read the appropriate env variables. process.env holds all the Heroku environment variables. Use those to edit your package.json.
Related
From the documentation this driver looks great. I don't know how to install it so that I can use it though. I read somewhere that I should maybe use rebar? I looked at that documentation though and it appears to have the opposite problem. It says how to install it, but not how to use it.
Update
So it looks like after installing rebar, I can add the lines
{deps, [
{mysql, ".*", {git, "https://github.com/mysql-otp/mysql-otp",
{tag, "1.3.3"}}}
]}.
to my file rebar.config. I don't know what this does though. Do I have to compile or make this file now? Does rebar.config have to be in the same directory as my project? Right not the path to rebar.config is ~/rebar/rebar.config
Is it all correct to place my project so that it is a sibling to rebar in the file hierarchy?
Update
I ran ./rebar get-deps with the rebar folder and got
Pulling mysql from {git,"https://github.com/mysql-otp/mysql-otp",
{tag,"1.3.3"}}
Cloning into 'mysql'...
==> mysql (get-deps)
I still don't really know what this means though, and when I try compiling my erlang file I receive the result.
c(erlangFile.erl).
{error,non_existing}
rebar is a build tool for erlang.Please go through https://github.com/rebar/rebar/wiki/Rebar-commands for the commands.
After getting dependency, "rebar compile" is required to compile it.
For using the beam files, you have to give output beam path using Add Path to Erlang Search Path?
these methods.
Then you will be able to use it in your code.
Download your package, in this case
git clone https://github.com/mysql-otp/mysql-otp.git
Download a tool called rebar
git clone git://github.com/rebar/rebar.git
cd rebar
./bootstrap
Add the following to rebar/rebar.config
{deps, [
{mysql, ".*", {git, "https://github.com/mysql-otp/mysql-otp",
{tag, "1.3.3"}}}
]}.
Within the rebar/mysql-otp directory run
./rebar get-deps
Then within the same directory, run
./rebar compile
This will put a bunch of .beam files and .app file into the ebin/ directory
Next add the ebin/ directory to your path. You can update your $ERL_LIBS environment variable, run an include command within the erlang console like
1> code:add_pathz("~/rebar/mysql-otp/ebin").
or
1> code:add_pathz("rebar/mysql-otp/ebin")
And theres a few other ways to add it to your Erlang path.
Also, make sure mysql is also installed
Heres a few links with mysql installation instructions that worked for me
https://www.digitalocean.com/community/tutorials/how-to-install-mysql-on-centos-7
No package msyql-server available
If use npm build command to build a react app for production environment, we can get a build named folder. There are html, css and JavaScript in it, but the package.json file doesn’t exists.
If we use this file to set http proxy endpoint to connect API, we can’t run the app well because the endpoint can’t be found.
How to deal with this json file rightly in this case?
First if you have package.json of some Node-React application you can run in example windows CMD (terminal console) and make some folder there you put this package.json and navigate to this folder and then, there typing npm install. On this away you can prepare all what is need for this Node-React app. Exactly with this command starting make node_modules folder there stat install need package. Next step is make folders: src and public, there you put next file :
on Src folder App.js, index.js, App.css
on public folder index.html.
That is because in this package.json exists all what is need for starting application, but if you menually build package.json this can make with run npm.
init in CMD.
Use Proxy in package.json file you can use for example if you send some data in case client-server app. There you have in client for HTTP request axios, on server side express. In package.json file add row "proxy":"http://localhost:3001"
from server. For that plz. look How to set port for express server dynamically?
With the help of a YouTube tutorial, I am working on my first MEAN stack project. So far, I have created index.html, server.js and package.json files. When I installed Mongoose and Body-Parser using terminal, my package.json file stored in Documents showed updated dependencies for package.json like
{
"name": "njnjn",
"version": "0.0.1",
"dependencies": {
"body-parser": "^1.15.2",
"express": "^4.14.0",
"mongoose": "^4.7.5"
}
}
but I did not see updated dependencies on Atom which had something like
{
"name": "njnjn",
"version": "0.0.1",
"dependencies": {
"express": "^4.14.0"
}
}
So, I could not see the updated dependencies for Mongoose and body-parser on the package.json. I'm working on in Atom but I could see the updated dependencies for mongoose and body-parser on package.json in Documents.
I want the dependencies to be updated on both files: the one in Documents and the one I'm editing in Atom (I thought those files were supposed to be the same)
Also, when I tried saving my package.json on Atom(one without updated dependencies for Mongoose and body-parser), an error message popped up saying "Unable to save file: Permission denied." I don't think this error is associated with Atom only because I could not save my package.json file on Sublime as well.
How do I solve this problem so that dependencies for mongoose and body-parser will be updated on the package.json file in my text editor. And how can I save my package.json file on my text editor?
I tried searching everywhere for solution and saw a similar problem on Stack overflow for which the best solution told "to temporarily become root and edit the file:
sudo atom /path/to/file"
Because I'm new to Ubuntu, programming and command line, I did not understand the solution. Could you guys please help me?
you can set the permissions recursively.
sudo chmod -R 777 your file path
e.g.
sudo chmod -R 777 /path/to/file
for more information click on this link
"Permission denied" means that your current user have not the authentication to change the file. Only the owner of the files and root have the authentication to change them in default.
sudo+command means you will use root's authentication. This requires that your current user is in 'root' user group(That also means that your current user is in sudoers).
You can get more help here:https://en.wikipedia.org/wiki/Sudo
By the way, you are the owner of /home/yourUserName in default. Maybe your file should be created there?
This error occurs because of the following problem
1:- Those folders do you want to save your file is private that's why they say access denied
For salve, this problem follow the command
1 :- $ sudo su
2:- Go on that folder you want to save for example
$ cd Desktop
3:- $ chown -v user-name /foldername
I am very new to the concept of npm-install. Please throw some insights into where I might be going wrong. I have a .js file through which I am supposed to invoke a binary with some command line arguments.I did write package.json setting the main parameter to the javascript file and I am using preinstall script that compiles the code and creates a binary that is supposed to be used by my java script file.
Couple of questions:
How do I make package.json take this compiled binary as dependency for the js file?
npm install runs fine for me but I do not see any output folder whatsoever. I was hoping it would generate a .node_module in pwd and copy the contents onto bin/ folder in that. May be, I am missing something.
npm info prepublish test#0v.0.1
npm verb from cache <pwd>/package.json
npm verb readInstalled returning test#0.0.1
npm verb exit [ 0, true ]
npm info ok
Can someone please through some insights into this issue?
You don't have to include your binary file in package.json. If you're using Express, put it in the node-modules folder within the parent directory. Otherwise, you can either specify the whole path to the file where you call it or put the file in the parent directory. For global installations, the node-modules folder is usually created at: C:\Users\[Username]\AppData\Roaming\npm\node_modules.
I figured out a way to handle it. Using a js module and using my node as required in that module causes npm to setup my node in node_modules/ folder. I used a pre-install shell script to compile my binary and used the relative path to use the binary upon execution.
Thanks for all who replied.
I installed jekyll and run it from cli:
jekyll --server --auto
But when I change _config.yml I can't see that my changes where applied and I have to restart server every time.
I really need to restart server every time when I change _config.yml? Or there is some workaround?
I believe you are correct; that changes to _config.yml always require restarting the server.
After all, _config.yml provides options that you can override in the call to Jekyll. So it is unclear how auto should behave if an option is called on the command line run of jekyll which overrides some of the _config.yml settings, and then the config is edited. Which would take precedence then? the _config.yml or the original command line argument?
If you have the server running, you don't need to restart it. A (little bit) quicker way to is to run jekyll build or bundle exec jekyll build after editing your _config.yml file.
Parker Moore, maintainer of Jekyll, confirms that _config.yml changes are not autogenerated or picked up by a running, watching Jekyll server.
No I remember why we can't do this: if you change either source or destination, you're eff'd, so we said 👎 to this suggestion. Definitely use _data if you're using custom data. Otherwise, a quick ^C and restart should be 👌
https://github.com/jekyll/jekyll/issues/2302#issuecomment-43160557
I really need to restart server every time when I change _config.yml?
Or there is some workaround?
There is some workaround:
1) Install watchy.
npm i -D watchy
2) Restart on config change (for example as a package.json script)
"scripts": {
"restart": "watchy -w _config.yml -- bundle exec jekyll serve --drafts --watch",
(--drafts is unrelated, but I am assuming you do this locally in dev/authoring mode...)