Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

291
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda