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

238
Vistas
why is Requiring mongoose from local file is not working?

So I have the code

Directory/app/script.js:-

// MongoDb
// Connect to MongoDB through Mongoose
const mongoose = require('mongoose')
mongoose.connect('mongodb://localhost:27012/profiles')

// Requiring the Schemas
const SignIn = require('MongoDb/Models/profiles.js')

console.log(SignIn)

So what is wrong in the code. The console in the web says that require is not defined. Can you help me with how to go about it.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

There are two reasons you might get this error. Since you said

The console in the web says

I expect it is the first reason in your code

You are running the code in a web browser

Node.js is a stand-alone environment for running JavaScript. It is not a browser extension.

To run Node.js code, save it in a file with a .js file extension, then run it with:

node yourFile.js

If you want Node.js code and browser code to interact then the typical way is to write a server in Node.js that hosts a web service. Express.js is a popular way to do this. You can then use Ajax to make HTTP requests to that web service.

For bi-directional communication (as opposed to the request/response of Ajax) look at Socket.io.

You are using ECMAScript modules

Node originally used CommonJS modules which use module.exports and require.

Recent versions also support ECMAScript modules which use export and import.

Either switch to using import instead of require or change your configuration to use CommonJS modules.

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