Simplest way to deploy your Deno application with MongoDB database

Tutorial how to deploy a Deno app with MongoDB database with Qovery

Deno is a secure runtime for JavaScript and TypeScript based on the V8 engine and Rust programming language. It was created by Ryan Dahl, the same person who is the creator of good ol’ Node.js.

This article is not meant to teach you Deno, but it’s worth to mention its main cool features:

  • Secure by default, runs in a sandbox. No file, network, or environment access, unless explicitly enabled. You need to add flags to gain permissions.
  • TypeScript compiler baked in, works out of the box.
  • Has built-in utilities like a dependency inspector (deno info) and a code formatter (deno fmt).
  • Ships only a single executable file.
  • Decentralized packages. No more NPM packages / package.json. Packages are imported from URLs and are cached on the hard drive on load.
  • Extensive standard library.
  • ES Modules import syntax over require syntax.
  • Browser compatible API e.g. fetch.

Without further due, let's move on to next post section where we'll deploy a Deno application with MongoDB on scalable cloud platform.

Deployment

This tutorial show you how to deploy your Deno application with MongoDB database. Let's go!

Steps to deploy Deno with Qovery

  • Sign in to the Qovery web interface.

    Qovery Sign-up page

  • Deployment

    Deno sample application

    Get a local copy of the Deno sample project by forking it.

    Configure your project

    To deploy your Deno application connected to a MongoDB, you need to have a .qovery.yml file, and a Dockerfile (both provided in the sample project) at the root of your project.

    In this example we are using MongoDB v3.6

    After forking the sample application, you can check the content of .qovery.yml:

    $ cat .qovery.yml
    .qovery.yml
    application:
    name: my-application
    project: my-project
    publicly_accessible: true
    databases:
    - type: mongodb
    version: "3.6"
    name: my-db
    routers:
    - name: main
    routes:
    - application_name: my-application
    paths:
    - /

    Authorize the Qovery Github application to get access to your Github account. Once done, all new commits you push to your forked repository will trigger new deployments of the application.

    Connect Deno to MongoDB

    Credentials of your database are available via environment variables. Qovery injects environment vars at the runtime.

    To list all the environment variables available to your application, execute

    # List all environment variables
    $ qovery project env list
    Output
    SCOPE | KEY | VALUE
    BUILT_IN | QOVERY_JSON_B64 | <base64>
    BUILT_IN | QOVERY_BRANCH_NAME | master
    BUILT_IN | QOVERY_IS_PRODUCTION | true
    BUILT_IN | QOVERY_MY_APPLICATION_HOSTNAME | <hidden>
    BUILT_IN | QOVERY_DATABASE_MY_DB_DATABASE | <hidden>
    BUILT_IN | QOVERY_DATABASE_MY_DB_PASSWORD | <hidden>
    BUILT_IN | QOVERY_DATABASE_MY_DB_USERNAME | <hidden>
    BUILT_IN | QOVERY_DATABASE_MY_DB_PORT | <hidden>
    BUILT_IN | QOVERY_DATABASE_MY_DB_FQDN | <hidden>
    BUILT_IN | QOVERY_DATABASE_MY_DB_HOST | <hidden>
    BUILT_IN | QOVERY_DATABASE_MY_DB_CONNECTION_URI_WITHOUT_CREDENTIALS | <hidden>
    BUILT_IN | QOVERY_DATABASE_MY_DB_CONNECTION_URI | <hidden>
    BUILT_IN | QOVERY_DATABASE_MY_DB_VERSION | 3.6
    BUILT_IN | QOVERY_DATABASE_MY_DB_TYPE | MongoDB
    BUILT_IN | QOVERY_DATABASE_MY_DB_NAME | my-db

    The sample application is preconfigured to use those environment variables to connect to the database.

    Forking the application with .qovery.yml and a Dockerfile should trigger app deployment.

    See the deployment status by executing:

    # Show your deployment status
    $ qovery status
    Output
    BRANCH NAME | STATUS | ENDPOINTS | APPLICATIONS | DATABASES
    master | running | https://main-abcdefgh12345678-gtw.qovery.io | my-application | my-db
    APPLICATION NAME | STATUS | DATABASES
    my-application | running | my-db
    DATABASE NAME | STATUS | TYPE | VERSION | ENDPOINT | PORT | USERNAME | PASSWORD | APPLICATIONS
    my-db | running | MONGODB | 3.6 | <hidden> | <hidden> | <hidden> | <hidden> | my-application

    When your application status is running, you can use a browser or curl to access its endpoints.

    Trigger a new deployment

    Now, you can play with the sample application and commit & push your changes. Qovery detects your actions and triggers new builds and application deployments. Any change you make will be reflected in your deployed application automatically.

    Bonuses (optional)

    Deploy the application on dev environments

    Qovery has a compelling feature known as "environments". Qovery supports the deployment of isolated development environments that reflect your Git branches. Environments are complete copies of all of your data, application, and services like databases. The Environment is useful for testing changes in isolation before merging them to your main branch.

    So, do you want to create a new feature, fix a bug, or make modifications without impacting the production or any other important environment? Type the following commands:

    $ git checkout -b feat_foo
    $ git push -u origin feat_foo
    # show deployment status
    $ qovery status
    Output
    BRANCH NAME | STATUS | ENDPOINTS | APPLICATIONS | DATABASES
    feat_foo | running | https://main-yenr7erjbs87dk4m-gtw.qovery.io | my-application | my-db
    APPLICATION NAME | STATUS | DATABASES
    docker-simple-example | running | my-db
    DATABASE NAME | STATUS | TYPE | VERSION | ENDPOINT | PORT | USERNAME | PASSWORD | APPLICATIONS
    my-db | running | MongoDB | 3.6 | <hidden> | <hidden> | <hidden> | <hidden> | my-application
    Multiple Environments

    Test the Deno application locally

    The Qovery motto is: if your application runs locally, it runs well on Qovery, too. To test if your application is running locally, execute the following command:

    $ qovery run

    Note: qovery run connects your application to the MongoDB database on Qovery.

    Conclusion

    Congratulations! Now, you know how to deploy your Deno app with MongoDB in just a few steps.

    Do you have any feedback about this tutorial? Let us know what you think on Discord, and join our wonderful dev community of +600 devs.