I tried to create a 7 api on node.js to learn it out.
1.TO-DO LIST
I created a basic RESTful API using Express.js to manage a todo list. The API includes endpoints for retrieving all todos, adding a new todo, updating an existing todo, and deleting a todo. To handle JSON requests, I used the bodyParser middleware. Each todo is represented by an id
, task
, and completed
flag. Error handling is implemented to manage cases where a task is missing or an invalid todo ID is provided. The server runs on port 3001 and provides a straightforward interface for managing the todo list.
2.user-authentication API:I created an authentication system using Express.js, bodyParser, and jwt for JSON Web Token generation and verification.The system includes a login endpoint for users to authenticate with their username and password, issuing a JWT token upon successful authentication. Additionally, there is a protected endpoint that requires a valid JWT token to access. A middleware function verifies the token and grants access to the protected resource if the token is valid. The server runs on port 3000 and uses a secret key for JWT token generation and verification.
3.Chat API:I developed a real-time chat application using Express.js for the backend, Socket.io for real-time communication, and plain HTML/CSS/JavaScript for the frontend. The application serves static files from the 'public' directory, including an HTML file for the chat interface. Users can join the chat by entering a username, which is stored in an object to track connected users. Messages sent by users are broadcasted to all connected users, providing a seamless chat experience. The server runs on port 3000 by default but can be configured using the process.env.PORT
variable.
4.Bitcoin API:I created a simple Express.js server that provides a /bitcoin-price
endpoint. This endpoint uses the Axios library to fetch the current price of Bitcoin in USD from the CoinGecko API. If the request is successful, it returns the Bitcoin price as a JSON response. If there's an error during the request, it logs the error and returns a 500 status code with an error message. The server runs on port 3000 and logs a message to indicate that it's running.
5.Event manager:I developed a simple RESTful API using Express.js to manage a list of activities. The API includes endpoints for adding a new activity, retrieving all activities, and retrieving a specific activity by its ID. I used an in-memory array called activities
to store the activity data. The server runs on port 3000 and logs a message to indicate that it's running. This API provides a basic framework for managing activities and can be easily expanded with additional features as needed.
6.Payment API:I developed an Express.js server to handle payment processing using the Stripe API. The server includes two main endpoints: /payment
for creating a new payment intent and /webhook
for handling webhook events from Stripe. The /payment
endpoint accepts a JSON payload with details such as amount, currency, source, and description, then creates a new payment intent and responds with the client secret for the payment intent. The /webhook
endpoint listens for specific events like payment_intent.succeeded
and payment_intent.payment_failed
, and logs the event details accordingly. The server uses the express.json()
middleware to parse JSON request bodies and runs on port 3000. It logs a message to indicate that it's running. Overall, this setup provides a reliable and secure way to process payments using Stripe's payment platform.
7.Fitness Track API:I created an Express.js server to manage a list of activities. The server provides three endpoints: /activities
to add a new activity, /activities
to retrieve all activities, and /activities/:id
to retrieve a specific activity by its ID. The server uses an in-memory array called activities
to store the activity data. It also uses the express.json()
middleware to parse JSON request bodies. The server runs on port 3000 and logs a message to indicate that it's running. This API provides a simple way to manage and retrieve activities, making it useful for various applications.
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (0)