I am building a website where users are able to make appointment requests. The information goes to a mongo collection. Is it possible to send the information to an email as well as the mongo collection?
In other words, whenever the db receives a new entry I'd like for that entry to be sent to an email that I choose.
I would post some of the code but I don't have any context or idea where to start.
Yes it is possible.
You can google nodejs send email and you will find plenty of node modules that do that.
One example is Nodemailer module.
You will have a function where you store records to mongodb. Inside the same function, after insertion/update, you would call .sendMail function to send an email.
Related
I am trying to do a project where I want to send mails to the subscribers using Nodejs and Listmonk.
Whenever user registers to the website I want to add his/her email to Lismonk server and want to automatically send mail whenever some particular conditions are met!
Any idea how I can do that or any reference please share!!!
Thank You..
I'm quite new with sockets so I came here to ask for some good practice ideas.
To understand better what I want to achieve here is my idea: I made a product creation page in react which has a seller and an option "Send message to the seller". After a buyer clicks to this button I want to make a private chat between the two user.
I want to save this socket connection and all of the messages between the users for both of them in my MongoDB database. So whenever a user simply leaves the site all of the recieved contacts/messages are saved and when he rejoins can continue the chat with the pre-loaded chat history.
So I thought about creating a messages collection and store socket details in document like this:
_id:ObjectId("123")
productId:1
sender:id1
reciever:id2
messages=[{1:"Hey},
{2:"Nice to meet you"} ...]
And here comes the redux part: When a user is logging in, I want to fetch all of the previous contacts and messages so he can continue chatting with them. But it would be time waisting to fetch the message history every single time, so I thought about using a redux store to get the contacts and history from database and store there. Like this
recievedmessages=[{_id:ObjectId("123")
productId:1
sender:id1
reciever:id2
messages=[{1:"Hey},{2:"Nice to meet you"} ...]},
{othermessage1 ...},
{othermessage2 ...},
]
sentMessages=[{sentmessag1, sentmessage2, sentmessage3}]
And when a buyer sends a new message to that user I update my redux store for the buyer, when the seller recives the message from the socket update for him too and lastly my chat history in my mongodb messages field for that specific document. --> I am not sure at this part to have to manage it
Is this a good practice or how should I make this to be effiecent and store data? Thanks in advance.
currently i'am developing a react app where user can post and comment and like a post.
so i did everything but there is one more thing that i want to do which is getting notification after user
Post or maybe comment and so on..
so let say i have a table called 'posts' in the database (PostgreSQL) and when user called "A" create post ,that post inserted into the database and then i want to receive a notification which Said that the user "A" created a post with the ID of that post and i think the main idea here is to watch the table of posts and whenever a new raw inserted a notification fire.
i searched many sources and find that i can use Pusher ,web-socket but to be honest i can't make a decision without figuring out the best way to achieve that.
So How i can get notified hence a new row inserted into the table "posts" ?
Thank you in advance.
Postgres has LISTEN/NOTIFY that you could use in conjunction with an on-insert trigger on the posts table.
Some process can then be listening for those notifications and figure out whom to send the notification to (via whichever transport you choose).
However, I think you might be better off adding a concrete table for notifications, so the user can see notifications that occurred when they weren't connected to the notification transport.
I have an admin panel in my Node.JS application where admins can login and send emails to groups of users. Sometimes these groups can contain up to 1,000 people. When the admin composes an email in the admin panel and hits the send button, I grab each row from the database and generate a unique link for that email body and then send it using the #sendgrid/mail npm package. I have looked at the following page and it is helpful: https://github.com/sendgrid/sendgrid-nodejs/blob/master/use-cases/README.md#email-use-cases
However, I don't know if it's more efficient to create a giant array of emails and dump that into one of the libraries methods, or if I should loop through and make a separate method call in each iteration and use Promise.all. I suppose I need a solution that won't make the Sendgrid rate limits angry but also not keep my http request loading for 30 seconds for the admin.
Thank you
From the UI you should get all the users that are to be emailed, into the node.js backend app.
In the backend app, assuming you get an array of the users, you use the Arrays.map() method to execute a function returns a promise that will send out the email.
You can then use Promise.all() to see what emails got send and what failed.
If there are any failures you can show that as a notification to the Admins on the UI, for only those users that failed.
Also note the SendGrid API seems to be capable of accepting 10k requests per second. Do take a look at this.
MERN stack
In my app, you can follow users and when those users make a post, you should get a notification.
Currently, my User model has an array that lists all the users they're following as well as users who are following them:
users_you_follow: [ <object_ids>... ],
users_who_follow_you: [ <object_ids>... ]
My current idea looks something like this:
When a user makes a post in the frontend, we pass in the array of users_who_follow_you as well as the post details into the backend.
Then, using mongoose, parse the users_who_follow_you and find the users with the same ID's.
Finally, within that User model, I would store the post details along with some other metadata.
Then in the frontend, I would have a setInterval call to check if there are any new notifications.
This method although might work seems very server intense with all the API calls to check notifications. Is there a better way around this?
I currently don't know how to start on this process. From my research, some people said to use websockets while others say web workers.
What would be the best way to achieve something like this?
A very similar system to compare it to would be StackOverflows inbox thing. If a user comments on your post, the header/navbar shows a notification without having you to refresh your screen.
Thank you.