I'm most of the way there, has anyone gotten it to succesfully work? I only have the database working locally, after I git push heroku master the connection to the database fails.
Add 'Heroku Postgres' either through the Heroku CLI or under your project's Resources tab. It should also give you a DATABASE_URL variable which you need for later.
Add pg module from Heroku. See the documentation here.
$ npm install --save --save-exact pg
Then, on the server, use the DATABASE_URL we just got.
const client = new Client({
connectionString: process.env.DATABASE_URL,
ssl: true,
});
client.connect();
Put "use_env_variable": "DATABASE_URL" on the config.json file under "production". Should look like
"production": {
"use_env_variable": "DATABASE_URL"
...
}
Run migrations on Heroku. An option if you want to use sequelize-cli is:
$ npm install sequelize-cli --save
$ heroku run sequelize db:migrate
And it should work.
Related
Im trying to make a deploy in Digital Ocean when i try to make a migration using sequelize cli but wehn i do it
npx sequelize db:migrate
its says a error in the terminal and says
ERROR: Cannot find "/home/deploy/app/config/config.json". Have you run "sequelize init"?
then i tri using
npx sequelize init
and create all the folders (migrations - models - config - seeders, etc) THEN i move my migrations to the folder created to try to fix the issue, then in the config/config.json y config all the bd config, and try it again but says the same issue all the time
how can i fix that please i need to make this deploy can someone helps me?
I have solved it using
npx sequelize db:migrate WORKDIR /myapp/path
I am currently learning Node.js (with Express, Postgres, Sequelize) and have a very simple (API) app running locally (it's working, tried with Postman) I now want to deploy to Heroku. I have some basic Heroku knowledge as I've used Rails in the past, but I am stuck with some things Rails handles behind the scenes.
I've set up a config.js file with some production credentials generated when running npx sequelize-cli init, I've updated my local settings (this works!) but what do I need to add as my production credentials? Do I need to provide them on my own? Or are those provided by Heroku?
Please note — I've already setup my pipeline and app as well as Postgres on Heroku but when trying to connect to my app via the cli, e.g. heroku run bash --app name-of-my-app and running npx sequelize-cli db:create it gives me the following error:
Loaded configuration file "config/config.js".
Using environment "production".
TypeError: Cannot read property 'replace' of undefined
at Object.removeTicks (/app/node_modules/sequelize/lib/utils.js:347:12)
at Object.quoteIdentifier (/app/node_modules/sequelize/lib/dialects/abstract/query-generator/helpers/quote.js:50:35)
at PostgresQueryGenerator.quoteIdentifier (/app/node_modules/sequelize/lib/dialects/abstract/query-generator.js:891:24)
at getCreateDatabaseQuery (/app/node_modules/sequelize-cli/lib/commands/database.js:77:50)
at Object.exports.handler (/app/node_modules/sequelize-cli/lib/commands/database.js:45:17)
Further notes:
I am using Node 14.0.0 and sequelize 6.3.0
I've added "engines": { "node": "14.x" } to my package.json
I don't have a procfile as Heroku states it's not needed anymore
My app entrypoint is app.js
Putting this up here, in case someone else is having similar troubles:
Just figured it out, it's actually pretty straight forward but I was a bit confused by the default config.js setup provided when running npx sequelize-cli init.
this is what my production settings look like:
production: {
use_env_variable: 'DATABASE_URL',
dialect: 'postgres'
}
i'm a beginner and i'm trying to deploy a back-end application. I'm using an aws EC2 with ubuntu server and the problem is as follows. in the application on my machine the command "yarn sequelize db: migrate" runs normally, executes the migrations and creates the tables. but not on the server. I already changed the environment variables, even put the information directly in the code, even so it does not run the migrations. the most it does is: deploy#ip-xxx.xxx.xxx.xxx: ~ / app / server $ yarn sequelize db: migrate
yarn run v1.22.4
$ /home/deploy/app/server/node_modules/.bin/sequelize db: migrate
Sequelize CLI [Node: 14.4.0, CLI: 5.5.1, ORM: 5.21.6]
Loaded configuration file "src / config / database.js".
Done in 0.54s.
It is as if I did not enter the migrations folder for any reason
i'm using postgres on docker image.
TL;DR: try to use the latest version for all the dependencies for sequelize-cli, as shown in the last code block of this response.
I am not 100% sure if this is the same issue I encountered. But I have been stuck in a similar situation for 2 days. Basically when I run "npx sequelize db:migrate", it will show the following,
Sequelize CLI [Node: 14.4.0, CLI: 5.5.1, ORM: 5.21.6]
Loaded configuration file "src / config / database.js".
Using environment "development".
Then it just stopped there! I dived deep into the sequelize-cli library and put some console log statements in to see what's failing. Eventually I found that somehow it's failing in
return sequelize.authenticate().then(() => {
this line in the /sequelize-cli/lib/core/migrator.js
Eventually, it got me wondering if this is an external dependency issue. Then I use the latest dependencies, as following in my package.json
"dependencies": {
"pg": "^8.2.1",
"sequelize": "^5.21.13",
"sequelize-cli": "^5.5.1"
},
I realized that I was previously using "pg": "^7.18.2". Then this fixed the issue for me.
I am trying to setup locally an existing Heroku app. To do so, I git cloned the app from our repo in Github. Then I added the git remote for heroku.
Normally, builds to the server happen with Travis CI, but now I want to run the app locally straight from heroku.
heroku config returns the config variables just fine.
But heroku local web returns the error
throw new Error('Configuration property "' + property + '" is not defined');
Error: Configuration property "redis.url" is not defined
redis.js
import config from 'config';
const redis = new Redis(config.get('redis.url'), {
keyPrefix: 'kw:',
});
The config folder is in the root of my repo.
config/default.js
import dotenv from 'dotenv';
dotenv.config({ silent: true });
module.exports = {
...,
redis: {
url: process.env.REDIS_URL || process.env.REDISCLOUD_URL,
},
...
}
Relevant scripts in package.js
"start:server": "./node_modules/.bin/babel-node src/server.js",
"start:worker": "./node_modules/.bin/babel-node src/worker/worker.js",
"start": "./node_modules/.bin/nf start",
If I run npm run start:server I get the same error.
If I comment out the redis.url code I get the same error but for another variable in the config.
What am I missing? Let me know if you require clarification.
I had to create a local .env file.
I got confused because I was reading that you dont need a .env file with Heroku. But this is not the case for local setups it seems.
heroku config -s > .env
will copy those files to the local .env it seems. seems strange that this isn't the default, but so it goes.
Once you do that, run your app with heroku local.
I found the answer here: https://www.debugcn.com/en/article/31153943.html
I'm trying to deploy my feathersjs web app on heroku, and since feathers is simply an express wrapper I thought it was like deploy an ordinary node app. I got the "npm start" script on my package.json, I added heroku remote to my git repo and when I push heroku run "yarn install" and the "npm start" script. But just when the app start, an error occurs:
heroku logs
I can't figure out what happen, any suggestions?
Maybe I could dockerize my app, someone could help me to find the proper implementation?
Thanks everybody
It is the same as Express but the generated application will by default use feathers-configuration to pull in your application settings. From the error message it looks like you are not providing a proper NODE_ENV environment variable which has to be set to production when deploying to Heroku.
Working port of feathers-chat app to Heroku PostgreSQL via Sequelize
I got a port of the hello world https://github.com/feathersjs/feathers-chat running on Heroku right now!
source: https://github.com/cirosantilli/feathers-chat/tree/sequelize-pg
live until it breaks: https://cirosantilli-feathersjs-chat.herokuapp.com/
Key source changes
Set 'postgres' to the DATABASE_URL environment variable config/production.json:
+ "postgres": "DATABASE_URL"
Heroku also exports PORT which was also already in that file before my patch.
Pass dialiectOptions to the DB connection as per: Can't connect to heroku postgresql database from local node app with sequelize
+ const sequelize = new Sequelize(connectionString, {
+ dialect: 'postgres',
+ logging: false,
+ define: {
+ freezeTableName: true
+ },
+ dialectOptions: {
+ // https://stackoverflow.com/questions/27687546/cant-connect-to-heroku-postgresql-database-from-local-node-app-with-sequelize
+ // https://devcenter.heroku.com/articles/heroku-postgresql#connecting-in-node-js
+ // https://stackoverflow.com/questions/58965011/sequelizeconnectionerror-self-signed-certificate
+ ssl: {
+ require: true,
+ rejectUnauthorized: false
+ }
+ }
+ });
Key Heroku settings
enable the PostgreSQL Heroku add-on with:
heroku addons:create heroku-postgresql:hobby-dev-
This automatically sets the DATABASE_URL environment variable for us.
in config/production.json edit host to your correct value
in the Heroku app Settings, set the NODE_ENV environment variable to production
Bibliography:
https://github.com/feathersjs/feathers/issues/1647
try set "NODE_CONFIG_DIR" to "app/config/"