Use a hosted database with Zeit’s Now

Share this video with your friends

Send Tweet

If you need to persist data using now, it’s recommended that you use a hosted database service. In this lesson we'll create a new, free MongoDB database on http://mlab.com and wire it up to use with our node.js app running on Zeit's now hosting service.

Jacek
Jacek
~ 8 years ago

You could also use a docker container to spin up your app with any database you want, right?

mykola bilokonsky
mykola bilokonsky(instructor)
~ 8 years ago

No, absolutely not! You have no control over the instance(s) where your app runs. Other than a small temp folder you cannot assume persistence of any file system writes, which means your database can and will fragment when autoscaling!

Michael Wills
Michael Wills
~ 8 years ago

@mykola Is there a way to use .env? I believe on the zeit Slack I have seen the use of dotenv by having something like

cp dev.env .env && now && rm .env

or something along those lines. Has that improved?

Thanks!

mykola bilokonsky
mykola bilokonsky(instructor)
~ 8 years ago

That's a great question, I'll see if I can dig something up. I believe your package.json file can define now.env and have the keys -> values there be exported automagically, but obviously only do and commit this to your repo if you're using now secrets via @secretname as your values.

Jean-Marc Giorgi
Jean-Marc Giorgi
~ 7 years ago

Hi there, your example is based on the mlab service. Would it be possible to do the same thing with Mongodb Atlas? Thanks