After having everything working on my Heroku app for months, I started getting this error yesterday:
no pg_hba.conf entry for host "x.x.x.x", user "xxxxx", database "xxxxz", SSL off"
I've only been working on the client side and haven't changed anything on the server, so I don't know what could be going on.
server package.json
{
"name": "spiral-server",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "mocha --require test/setup.js",
"dev": "nodemon src/server.js",
"start": "node src/server.js",
"migrate": "postgrator --config postgrator-config.js",
"migrate:test": "env NODE_ENV=test npm run migrate",
"migrate:production": "env SSL=true DATABASE_URL=$(heroku config:get DATABASE_URL) npm run migrate",
"predeploy": "npm audit",
"deploy": "git push heroku master",
"postdeploy": "npm run migrate:production"
},
"keywords": [],
"engines": {
"node": "12.14.1"
},
"author": "",
"license": "ISC",
"dependencies": {
"cors": "^2.8.5",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"helmet": "^4.1.0",
"jsonwebtoken": "^8.5.1",
"knex": "^0.21.5",
"morgan": "^1.10.0",
"pg": "^8.3.3",
"postgrator": "^4.0.1",
"postgrator-cli": "^3.2.0",
"xss": "^1.0.8"
},
"devDependencies": {
"chai": "^4.2.0",
"mocha": "^8.1.1",
"nodemon": "^2.0.4",
"supertest": "^4.0.2"
}
}
I'm not sure how to start debugging, when I already had it working perfectly.
The only change I might have made was to the GitHub repo name (I changed a few repo names, and not sure if I changed this one or not)
All my other work has been on the client which is a React app hosted on Vercel.
I get the pg error when I query from localhost, Vercel, or Postman.
Any suggestions?
Try the following.
Add a new PGSSLMODE env variable with require as value under your app settings in Heroku.
Then restart your dyno...
heroku ps:restart
Related
I want to run the npm command 'npm audit fix --force', because I already ran 'npm audit fix' and there are still vulnerabilities, is there a way I can somehow fix all the vulnerabilities without breaking my program, I tried running the command in a cloned file to see what damage it would cause, and you guessed it, it broke.
Is there a way I can somehow modify the package.json and package-lock.json to fix this?
Here is my package (making a login and registration system via mongodb)
{
"name": "passport-local-register-login",
"version": "2.0.0",
"description": "Node.js authentication with Passport",
"main": "app.js",
"scripts": {
"start": "node app.js",
"dev": "nodemon app.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"bcryptjs": "^2.4.3",
"connect-flash": "^0.1.1",
"ejs": "^2.6.1",
"express": "^4.16.4",
"express-ejs-layouts": "^2.5.0",
"express-session": "^1.15.6",
"mongoose": "^5.7.5",
"passport": "^0.4.0",
"passport-local": "^1.0.0"
},
"devDependencies": {
"nodemon": "^1.18.9"
}
}
I have a Svelte app deployed to Heroku. This is a legacy code, at first I had 500 error, but after I installed serve the 500 error is gone, but I get the abovementioned 404. I have created another folder on my computer and pulled this very app from Heroku with heroku git:clone -a , ran npm install and it works like a charm locally. I do not get any errors in the console nor in my IDE. I found solutions saying that pushing my build folder can help, but so I did and nothing.
Would someone please pint me to the proper solution, this is my package.json, if necessary I will provide other data.
{
"private": true,
"name": "x",
"description": "y",
"version": "2.0.111",
"license": "MIT",
"scripts": {
"predeploy": "npm version patch && git push && git push --tags",
"deploy": "git push -f heroku master",
"heroku-postbuild": "run-p build",
"dev": "sapper dev",
"build": "sapper build --legacy",
"export": "sapper export --legacy",
"start": "serve -s build",
"cy:run": "cypress run",
"cy:open": "cypress open",
"test": "run-p --race dev cy:run"
},
"dependencies": {
"compression": "^1.7.1",
"lodash-es": "^4.17.15",
"polka": "next",
"serve": "^12.0.0",
"sirv": "^0.4.0"
},
"devDependencies": {
"#babel/core": "^7.0.0",
"#babel/plugin-syntax-dynamic-import": "^7.0.0",
"#babel/plugin-transform-runtime": "^7.0.0",
"#babel/preset-env": "^7.0.0",
"#babel/runtime": "^7.0.0",
"npm-run-all": "^4.1.5",
"rollup": "^1.12.0",
"rollup-plugin-babel": "^4.0.2",
"rollup-plugin-commonjs": "^10.0.0",
"rollup-plugin-json": "^4.0.0",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-replace": "^2.0.0",
"rollup-plugin-svelte": "^5.0.1",
"rollup-plugin-terser": "^5.1.1",
"sapper": "^0.27.0",
"svelte": "^3.0.0"
},
"repository": {
"type": "git",
"url": "git#github.com:confrontjs/2019.confrontjs.com.git"
}
}
Thanks!
I have a react + express project where I do server side rendering. My folder structure is like this
root
client
build
node_modules
public
src
package.json
node_modules
routes
server.js
package.json
I have two Heroku dynos app-dev and app-prod and I use app-dev for development and app-prod for production and their environments have been set to dev and prod accordingly. My package.json looks like this
{
"name": "name",
"version": "1.0.0",
"description": "",
"main": "server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server",
"server": "nodemon server",
"client": "npm start --prefix client",
"build": "cd client/ && npm install && npm run build",
"dev": "concurrently \"npm run server\" \"npm run client\""
},
"author": "",
"license": "ISC",
"dependencies": {
"body-parser": "^1.18.3",
"chalk": "^4.1.1",
"concurrently": "^6.1.0",
"connect-mongo": "^3.2.0",
"cookie-parser": "^1.4.3",
"cookie-session": "^2.0.0-beta.3",
"cors": "^2.8.5",
"dotenv": "^10.0.0",
"express": "^4.16.4",
"express-session": "^1.15.6",
"express-validator": "^6.11.1",
"mongoose": "^5.4.1",
"mongoose-findorcreate": "^3.0.0",
"morgan": "^1.10.0",
"passport": "^0.4.0",
"passport-google-oauth": "^2.0.0",
"passport-google-oauth20": "^2.0.0",
"passport-twitter": "^1.0.4",
"redux-thunk": "^2.3.0",
"http-proxy-middleware": "^2.0.0"
}
}
Now I have got a constants file in my client/src folder that had these
// Constants.js
const prod = {
url: {
SS_API_URL: 'https://prod.example.com',
},
keys:{
SS_CLIENT_ID: 'prodClientId',
SS_X_API_KEY: 'prodApiKey',
}
};
const dev = {
url: {
SS_API_URL: 'https://dev.example.com',
},
keys:{
SS_CLIENT_ID: 'devClientId',
SS_X_API_KEY: 'devApiKey',
}
};
export const config = process.env.NODE_ENV === 'development' ? dev : prod;
Now when I upload to Heroku (app-dev) and it builds it, after that it seems to be using the prod.example.com instead of dev.example.com API endpoint. Since the NODE_ENV is development I thought it would take the SS_API_URL for dev but it is taking the SS_API_URL for prod
You can add this variable on settings menu, "Config Vars", inside your heroku project. So you add NODE_ENV and value "production".
I have a project that is using express for the backend API. The project is working on my local machine but when I try to deploy it on a linux VM I get the error "Cannot find module 'Express'".
The steps I took to produce this error were cloning and cding into the repo, and running npm install. express is listed as a dependency in the package.json file. I tried explicitly running npm install express and npm install -g express and both said that they added and/or updated packages and did not return any errors. I also looked in the node_modules folder and there is an express folder there as well.
My package.json:
{
"name": "user-backend",
"version": "1.0.0",
"private": true,
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev-start": "nodemon server.js",
"nvm-start": "nvm use 8.11.3",
"postnvm-start": "nodemon server.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"axios": "^0.18.0",
"bcryptjs": "^2.4.3",
"body-parser": "^1.18.3",
"cors": "^2.8.4",
"dotenv": "^6.0.0",
"express": "^4.16.3",
"faker": "^4.1.0",
"helmet": "^3.12.1",
"jsonwebtoken": "^8.3.0",
"mongoose": "^5.2.2",
"morgan": "^1.9.0",
"request": "^2.88.0",
"slugify": "^1.3.1",
"validator": "^10.4.0"
},
"devDependencies": {
"nodemon": "^1.18.1"
}
}
Any help would be greatly appreciated. Thank you
This ended up being a simple syntax error in my import ("Express" vs "express")
To clarify the issue:
I have built a node server, which works fine. But on pushing to git and cloning elsewhere, it doesn't work in the new location.
Cleared node_modules, and tried npm install.
gitignore has only node_modules directory in it.
package.json contains the following
{
"name": "node-todo-api",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node server/server.js",
"test": "export NODE_ENV=test || SET NODE_ENV=test && mocha server/**/*.test.js",
"test-watch": "nodemon --exec 'npm test'"
},
"engines": {
"node": "6.2.2"
},
"author": "",
"license": "ISC",
"dependencies": {
"bcryptjs": "^2.4.3",
"body-parser": "^1.15.2",
"express": "^4.14.0",
"jsonwebtoken": "^8.3.0",
"lodash": "^4.15.0",
"mongodb": "^2.2.5",
"mongoose": "^4.5.9",
"validator": "^5.6.0"
},
"devDependencies": {
"expect": "^1.20.2",
"mocha": "^5.2.0",
"nodemon": "^1.10.2",
"supertest": "^3.1.0"
}
}