MedusaJS error initializing the database ERR_INVALID_URL

1.3k Views Asked by At

I am trying to run MedusaJS locally, I have installed PostgreSQL/Medusa, and when I try to run it I get the error:

TypeError [ERR_INVALID_URL]: Invalid URL
    at new NodeError (node:internal/errors:399:5)
    at URL.onParseError (node:internal/url:566:9)
    at new URL (node:internal/url:646:5)
    at parse (c:\repo\medusa-store\node_modules\pg-connection-string\index.js:29:14)
    at new ConnectionParameters (c:\repo\medusa-store\node_modules\pg\lib\connection-parameters.js:56:42)
    at new Client (c:\repo\medusa-store\node_modules\pg\lib\client.js:18:33)
    at BoundPool.newClient (c:\repo\medusa-store\node_modules\pg-pool\index.js:213:20)
    at BoundPool.connect (c:\repo\medusa-store\node_modules\pg-pool\index.js:207:10)
    at c:\repo\medusa-store\node_modules\typeorm\driver\postgres\PostgresDriver.js:1163:18
    at new Promise (<anonymous>) {
  input: 'postgres://user:pass@host:port/db',
  code: 'ERR_INVALID_URL'

Is this not the correct format for the connection string?

postgres://[user][:password]@[host][:port]/[dbname]

I have checked the documentation for medusa and that seems to be the expected format for the connection string.

1

There are 1 best solutions below

0
On

there few things to consider when having an error related to postgres in medusajs or any database related error in medusa :

  1. first be sure that the url of DATABASE_URL enviroment variable structure is valid from docs:
DATABASE_URL=postgres://[user][:password]@[host][:port]/[dbname]
  1. be sure that you run the migrations before starting the backend :
medusa migrations run 
  1. be sure that postgres is installed correctly on your machine and psql driver is installed even if you are using postgres on a docker container
  2. if you are using postgres which is installed over a network be sure to allow it on the firewall .