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.
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
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.
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.