I am new to Node.js
and I am building an app to that stores image file. But I am not sure what should the type of image be?
const userSchema = new mongoose.Schema({
userImage: {
type: String,
required: true
}
})
I am new to Node.js
and I am building an app to that stores image file. But I am not sure what should the type of image be?
const userSchema = new mongoose.Schema({
userImage: {
type: String,
required: true
}
})
You have multiple options.
1. Convert the image to base64
and store it as string
(I would not recommend doing so, since this might be very slow for larger images)
2. Store the image as Buffer
3. Upload the image to a CDN / S3 / some other file storage and save the path to the image as string
in your database (recommended for performance)