Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

293
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda