1

I am very new to nodejs and trying to create a registration API using nodejs, I search for it and got some code but the problem is developer is using MongoDB but I am using MYSQL. So my question is how to create a schema in MYSQL using nodejs, I got the code where developer created the schema in MongoDB.

Here is the code:

const mongoose = require('mongoose');

const Schema = mongoose.Schema;

const userSchema = new Schema({
    email: String,
    password: String,
});

module.exports = mongoose.model('user', userSchema, 'users');

Also Why we need schema in the first place can't I just create table in my database manually and Insert data using Insert Query.

Thanks.

Ayush Verma
  • 103
  • 2
  • 10

1 Answers1

1

You don´t need a specific schema if you are using mySQL. The database itself has a schema and won´t give you the chance to store malformed data if configured correctly. Mongoose provides a schema for mongoDB, because mongoDB is schema-less. You can store any kind of data and you won´t get an error back if malformed data was stored. But of course if you are using TypeScript, you can build an interface or a class and validate data before storing without the use of any kind of third-party package

lstnrs
  • 119
  • 3