'TypeError: mssql.Schema is not a constructor
As I'm new to reactJS, someone Please help me to fix the below issue. below code was a reference from a learning tutorial.I have tried a lot to get it fixed, but no luck.
following is the code from User.js file :
const mssql = require("mssql");
const UserSchema = new mssql.Schema({
username:{
type:String,
require:true,
min:3,
max:50,
unique:true,
},
email: {
type: String,
required: true,
max: 50,
unique: true,
},
password: {
type: String,
required: true,
min: 6,
},
},
{timestamps:true}
);
module.exports=mssql.model("User",Schema);
following is the code from Auth.js file :
const router = require("express").Router();
const User = require("../models/User");
//REGISTER
router.get("/register", async (req, res)=>{
const User = await new User({
username:"****",
email:"***",
password:"***"
})
User.save();
});
module.exports=router
Error I received:
const UserSchema = new mssql.Schema({
^
TypeError: mssql.Schema is not a constructor
at Object.<anonymous> (C:\Users\vadiv\Desktop\LearnReactJS\models\User.js:3:20)
at Module._compile (node:internal/modules/cjs/loader:1103:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (C:\Users\vadiv\Desktop\LearnReactJS\routes\auth.js:2:14)
at Module._compile (node:internal/modules/cjs/loader:1103:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157:10)
[nodemon] app crashed - waiting for file changes before starting...
Solution 1:[1]
const mssql = require("mssql");
const UserSchema = new mssql.Schema({
username:{
type:String,
require:true,
min:3,
max:50,
unique:true,
},
email: {
type: String,
required: true,
max: 50,
unique: true,
},
password: {
type: String,
required: true,
min: 6,
},
},
{timestamps:true}
);
module.exports=mssql.model("User",UserSchema );
Simple mistake use this code
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Vijay |
