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

296
Views
fastify-mongoose no funciona, node.js y 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: el parámetro uri es obligatorio en D:\Users\Antonio\Desktop\Antonio\Work\GitHub\NextLevel\src\main.js:30:15

El problema es con fastify-mongoose, o probablemente con fastify-env. Me explico: si escribo directamente la URI en el parámetro URI, funciona. Pero usando variables de entorno no..

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

0

¿Está utilizando dotenv, porque debería? No le aconsejo que ponga contraseñas en su código o acceda a sus API.

 require('dotenv').config()

recordemos que cuando empezamos

 start()

comenzamos fastify y se debe invocar dotenv; de lo contrario, no se incluirá process.env.YOUR_VARIABLE

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!