/news-microservice

News Management Node.js App using TypeScript and Dependency Injection. Connecting to a MongoDB Atlas Free tier instance.

Primary LanguageTypeScript

news-microservice

News Management Node.js App using TypeScript and Dependency Injection

This is a simple News Management Node.js application developed using TypeScript and tsyringe. The app demonstrates the use of dependency injection with tsyringe to manage dependencies and provide a NewsService to handle news-related operations.

Libs

  1. tsyringe
  2. reflect-metadata

Database

For Dev we use a MongoDB Free tier cluster https://cloud.mongodb.com/

Getting Started

To run the application locally, follow the steps below:

Prerequisites

  • Node.js and npm should be installed on your machine.
  • Define following ENVIRONMENT variables.
    • DB_CONN_STRING
    • DB_NAME
    • COLLECTION_NAME

Installation

  1. Clone this repository to your local machine.

  2. Install the required dependencies using npm:

    npm install

Running the App

  1. Build the TypeScript code using:

    npm run build
  2. Start the application:

    npm start

The app should now be running locally at http://localhost:3000.

Usage

The application provides simple APIs for managing news articles. The news data is loaded from a sample JSON file stored in the data folder.

Endpoints

  • GET /news: Get all news articles.
  • GET /news/:id: Get a specific news article by ID.
  • POST /news: Create a new news article. (Note: TODO)
  • PUT /news/:id: Update a news article by ID. (Note: TODO)
  • DELETE /news/:id: Delete a news article by ID. (Note: TODO)

References

  1. Mongodb with Typescript

Contributing

Contributions are welcome! Feel free to submit issues, suggest improvements, or open pull requests.

License

This project is licensed under the MIT License.