Frequently Asked Questions
This involves building an Express.js application with API endpoints to create appointments, which are stored in MongoDB. A background scheduler uses node-cron to check for upcoming appointments and triggers the Plivo SMS API to send reminders based on the stored data.
Plivo is a cloud communications platform that provides the SMS API used to send appointment reminders. The project leverages Plivo's Node.js SDK to integrate SMS functionality seamlessly.
MongoDB's flexibility makes it suitable for storing appointment details, including name, phone number, time, and timezone. Mongoose simplifies database interactions within the Node.js application.
The tutorial sets up reminders to be sent 15 minutes before the appointment time. This time window is configurable within the application's reminder service.
Node-cron is used to schedule a task that runs every minute to check for upcoming appointments. The cron expression '/1 *' defines this schedule, and the timezone is set to UTC for consistency.
Express-validator is middleware used for validating incoming requests to the API. It checks the request body for required fields (name, phone, time, timezone) and ensures data is in the correct format before it reaches the controller logic.
The application uses date-fns-tz and Luxon to handle timezones. The user provides their local timezone when creating an appointment, which the app converts to UTC for consistent storage and scheduling, preventing issues with daylight saving time.
Node.js version 16 or later is recommended for this project. This ensures compatibility with the latest features and dependencies used in the tutorial.
The tutorial recommends creating directories for config, controllers, models, routes, services, utils, logs, and tests, promoting organized code and separation of concerns. This structure helps maintainability as your project grows.
Winston provides robust logging capabilities, essential for monitoring in a production environment. It logs to both the console and separate files, recording different log levels, messages, metadata, and error stack traces.
Yes, the message content can be customized within the reminder service logic. The provided example includes the appointment time and customer name, but you can modify this template to suit your needs.
The Plivo service logs errors when sending SMS messages fails and rethrows them to be handled by the caller. For production, add retry logic using techniques like async-retry or a retry counter in the appointment model.
API credentials (Auth ID, Auth Token) are stored as environment variables in a .env file, which should never be committed to version control. The dotenv package loads these variables into the application's environment.
The process includes creating a project directory, initializing npm, installing required dependencies, configuring nodemon (optional), creating an .env file for credentials, and structuring project files into appropriate folders.
The tutorial suggests testing the POST /api/appointments endpoint with tools like curl or Postman. Example curl commands and expected JSON responses for success and validation errors are provided.