Moonglade

Modern Markdown blogging with AI-powered localization and search.


NestJS pg template

This article introduces a backend project template based on NestJS, PostgreSQL, and TypeORM, aimed at providing a standardized development foundation. The article first outlines the configuration management approach, which involves reading YAML files and combining them with class-validator for strict data validation and transformation, ensuring the security and standardization of configurations. Next, it demonstrates how to use Docker Compose to quickly deploy Redis and PostgreSQL, optimizing the local development environment. The core functional modules include implementing database operations and migration management using TypeORM, as well as building a user authentication and permission control system based on JWT, Passport, and RBAC mechanisms, supporting dynamic retrieval of interface permission information via metadata. Additionally, the template integrates OpenAPI documentation generation and SDK automation tools to facilitate frontend integration. The logging system utilizes Winston and Dayjs to achieve Nest-style logging in development environments and file-based logging in production environments. Finally, the article covers specific data migration commands and a code submission process that follows the Conventional Commits specification, providing a complete technology stack reference for building robust, scalable enterprise-level backend applications.

Views 142
2024 daily nest node pgsql typeorm

Node.js backend Dockerfile example

This article introduces two Docker image build solutions based on Node.js, aiming to optimize image size and resolve environment dependency issues through layered build techniques. The first solution is designed for simple scenarios and adopts a three-stage build process: it first installs development dependencies, then executes build commands to generate artifacts, and finally integrates them into the production environment, striving to minimize the final image size. The second solution targets complex scenarios, focusing on resolving Linux graphics library dependencies required by the Canvas library, the Python runtime environment, and the installation of Chinese fonts. This solution configures domestic mirror sources to accelerate downloads and pre-installs Python and necessary system libraries in the production stage, ensuring the completeness and stability of the application runtime. Both solutions follow best practices by using multi-stage builds to isolate development, build, and production environments, effectively reducing redundant files in the final delivered image. Additionally, they ensure service availability through health check mechanisms, providing practical containerized deployment references for Node.js projects of varying complexity.

Views 144
ci-cd devops docker dockerfile fonts multistage-build node nodejs python web-service

Lite Version MongoDB Full-Text Search

This article primarily explores technical solutions for implementing Chinese full-text search in the MongoDB Community Edition. Since the Community Edition does not natively support Chinese word segmentation engines, the author proposes a custom solution based on NestJS, Mongoose, and the `@node-rs/jieba` segmentation library. The article details the use of Docker to deploy a MongoDB environment with replica set support, ensuring service stability through a health check mechanism. In terms of architecture, the project is organized using a Monorepo pattern. By listening to database change events, Chinese text is automatically segmented and written back to the collection upon data insertion, thereby constructing a full-text index that supports Chinese retrieval. This solution not only implements basic query functionality but also covers multi-entity detection, value object handling, and a comparative analysis with Elasticsearch, providing developers with a complete technical practice reference for achieving efficient Chinese search at low cost in constrained environments.

Views 175
docker fulltext mongodb nest node search study work

mongo-listener

This article introduces the design approach for building a data change monitoring service based on MongoDB oplog. Addressing the absence of binlog in MongoDB, it utilizes the watch API to achieve data heterogeneity and evaluates the pros and cons of embedding parsing logic within the database versus introducing third-party components. Architecturally, it adopts an independent microservice to simplify high-availability guarantees, with the core pipeline flowing from MongoDB through a Redis buffer before being delivered to Kafka. The introduction of Redis as a buffer aims to mitigate the risk of memory overflow caused by the disparity between production and consumption rates, while leveraging its persistence features to prevent message loss. The system implements checkpoint resumption by persisting the resumeToken and handles message duplication after restarts using a deduplication list. Regarding ordering, it flexibly selects ordered or unordered delivery based on business requirements and discusses batch sending to optimize performance. At the deployment level, it emphasizes secure configuration for Kafka and local execution of Redis. In summary, the current design focuses on single-node high availability, while multi-node consistency and complex query compensation mechanisms still require further refinement.

Views 109
High Availability MongoDB Change Streams kafka mongodb node redis