Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

290
Views
fastify-mongoose doesn't work, node.js and fastify
const ejs = require('ejs')
const path = require('path');
const fastify = require('fastify')();
const fastify_static = require('fastify-static');
const fastify_autoload = require('fastify-autoload');
const fastify_mongoose = require('fastify-mongoose');
const fastify_env = require('fastify-env');

let PORT;
let uri;

fastify.register(fastify_env, {
    dotenv: true,
    schema: {
        type: 'object',
        required: ['MONGO_URI', 'PORT'],
        properties: {
            MONGO_URI: {
                type: 'string',
                default: ''
            },
            PORT: {
                type: 'string',
                default: ''
            }
        }
    }
}).ready(err => {
    if (err) {
        throw new Error(err);
    }
    PORT = fastify.config.PORT;
    uri = fastify.config.MONGO_URI;
})

fastify.register(fastify_static, {
    root: path.join(__dirname, 'public'),
})

fastify.register(require('point-of-view'), {
    engine: {
        ejs: ejs,
    },
    root: path.join(__dirname, 'view')
})

fastify.register(fastify_autoload, {
    dir: path.join(__dirname, 'Logic/Routes'),
})

fastify.register(require('./Logic/Plugins/cache'))

fastify.register(fastify_mongoose, {
    uri: uri
})

const start = async () => {
    try {
        await fastify.ready();
        await fastify.listen(process.env.PORT);
        console.log('Listening on port: ', PORT);
    } catch (error) {
        throw new Error(error);
    }
}

start();

Error: Error: uri parameter is mandatory at D:\Users\Antonio\Desktop\Antonio\Work\GitHub\NextLevel\src\main.js:30:15

The problem is with fastify-mongoose, or probably with fastify-env. I explain: if i write directly the URI in the URI parameter, it works. But using environment variables no..

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Are you using dotenv, because you should, I don't advise you to put passwords in your code or access to your APIs.

require('dotenv').config()

let's remember that when we started

 start()

we starting fastify and dotenv has to be invoked, otherwise process.env.YOUR_VARIABLE will not be included

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!