prepare script does not read env_variables
See original GitHub issueHi all,
I’m not sure this issue is ONTOPIC, I just use some code from your example.
I have some issue to get the process.env
from a prepare script in package.json.
I’m trying to run mysql migration before starting the app but I can not fetch the process.env variables
My package.json
...
"scripts": {
...
"prepare": "npm run gcp-build",
"gcp-build": "node migrations.js",
},
...
My migrations.js
var path = require('path')
var mysql = require('mysql')
var migration = require('mysql-migrations')
require('dotenv').config()
var connection = mysql.createPool({
connectionLimit: 10,
host: process.env.DB_HOST,
user: process.env.DB_USER,
password: process.env.DB_PASS,
database: process.env.DB_NAME
})
migration.init(connection, path.join(__dirname, '/migrations'))
My app read the env_variables from app.yaml without problem but the prepare script do not.
Any help will be appreciated.
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
How to set environment variables from within package.json?
The NODE_ENV environment variable will be set by cross-env ... Then, in your package json, you will create a script that will set...
Read more >How To Use .env Variables In package.json - GenUI
The Problem. It's common to need access to your environment variables in multiple places. Your code, your build scripts, and your pipeline may...
Read more >How to use environment variables in NPM scripts safely ... - SwC
A blog post on the topic of: How to use environment variables in NPM scripts safely across operating systems.
Read more >Environment Variable Configuration on the Official Guides Not ...
I have worked on a project on macos for a while and started it up on a windows machine today and had this...
Read more >BASH script to set environment variables not working
When you run a script, it runs in a subshell. Variables are only valid within the context of that subshell. Set them in...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
That’s almost the same reproduction that I used 😄
Glad you found a solution. I opened a bug internally to clarify that in our docs, so other people don’t run in to the same problem. Thanks again for reporting!
I finally got my full deploy workflow working and
gcp-build
was failing to run db migration … then I found this issue …TABLE FLIP!