MongoDB and Mongoose

How can i connect to my database using glitch using .env file because its not responding to my database but all tutorials want us use a secrete file
am doing URL Shortener Microservice database course

I have moved your question into the Backend Development category as this best seems to match your query. Have a wonderful day.

Anyway generally speaking, you would follow the exact same process you would use for any other MongoDB provider. You would create a .env file with the connection string to your MongoDB database present as one of the variables. Then you would write the appropriate code using the dotenv package to read the variables and connect to the database with Mongoose.

The only thing that seems different is how you would write the .env file. It simplifies the process of creating environment variables for you.

More information on how Glitch lets you write variables here.

Hope this helps. :slight_smile:

glitch gives the error:
SyntaxError: Unexpected token .

11:03 AM

at Module._compile (internal/modules/cjs/loader.js:723:23)

11:03 AM

at Object.Module._extensions…js (internal/modules/cjs/loader.js:789:10)

11:03 AM

at Module.load (internal/modules/cjs/loader.js:653:32)

11:03 AM

at tryModuleLoad (internal/modules/cjs/loader.js:593:12)

11:03 AM

at Function.Module._load (internal/modules/cjs/loader.js:585:3)

11:03 AM

at Module.require (internal/modules/cjs/loader.js:692:17)

11:03 AM

at require (internal/modules/cjs/helpers.js:25:18)

11:03 AM

at Object. (/rbd/pnpm-volume/3168d3e9-a5ea-45c7-a483-d4b12d4a67a9/node_modules/mongodb/lib/index.js:6:17)

11:03 AM

at Module._compile (internal/modules/cjs/loader.js:778:30)

11:03 AM

at Object.Module._extensions…js (internal/modules/cjs/loader.js:789:10)