当前位置: 首页 > 软件库 > Web应用开发 > >

nodejs-app-architecture

Node.js App Architecture showcase
授权协议 Apache-2.0 License
开发语言 JavaScript
所属分类 Web应用开发
软件类型 开源软件
地区 不详
投 递 者 东方和煦
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

What is this repository for?

Node.js app architecture showcase in Typescript. You can start your Node.js projects building on this boilerplate.

For the old js version look at the branch javascript

Architecture Overview

The app is designed to use a layered architecture. The architecture is heavily influenced by the Clean Architecture. The code style being used is based on the airbnb js style guide

Data Layer

The data layer is implemented using repositories, that hide the underlying data sources (database, network, cache, etc), and provides an abstraction over them so other parts of the application that make use of the repositories, don't care about the origin of the data and are decoupled from the specific implementations used, like Mongoose ORM (MongoDb) that is used by this app.Furthermore, the repositories are responsible to map the entities they fetch from the data sources to the models used in the applications. This is important to enable the decoupling.

Domain Layer

The domain layer is implemented using services. They depend on the repository interfaces to get the app models and apply the business rules on them. They are not coupled to a specific database implementation and can be reused if we add more data sources to the app or even if we change the database for example from Postgres to MongoDB.

Routes/Controller Layer

This layer is being used in the express app and depends on the domain layer (services). Here we define the routes that can be called from outside. The services are always used as the last middleware on the routes and we must not rely on res.locals from express to get data from previous middlewares. That means that the middlewares registered before should not alter data being passed to the domain layer. They are only allowed to act upon the data without modification, like for example validating the data and skipping calling next().

Entry point

The entry point for the applications is the server.ts file. It does not depend on express.js or other node.js frameworks. It is responsible for instantiating the application layers, connecting to the db, mounting the http server to the specified port and handling the signals for graceful shutdown.

Quick start

Use Docker:

You can use Docker to start the app locally. The Dockerfile and the docker-compose.yaml are already provided for you.

Run the following command:

  • docker-compose up

Use the npm scripts:

Setup development environment with docker:

  • npm run start:dev.env to start the development environment (mongo database).

Run the service

  • npm run dev for starting the service using ts-node-dev to auto restart the server on changes.

Build app

  • npm run build to build the project.
  • npm start to start the server.

Packages and Tools

License

Copyright 2020 Alexandros Koufatzis.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
  • Node.js for Mobile Apps This is the main repository for Node.js for Mobile Apps, a toolkit for integrating Node.js into mobile applications. Resources for Newcomers This is the central repository for

  • Node.js for Mobile Apps This is the main repository for Node.js for Mobile Apps, a toolkit for integrating Node.js into mobile applications. Resources for Newcomers This is the central repository for

  • Node.js on Mobile This project is an experimental fork of nodejs/node-chakracore bringing Node.js to mobile operating systems, as a library that can be embedded in mobile applications and frameworks.

  • nodejs Recently I’ve been building a small application using Event-Sourcing in NodeJS. 最近,我一直在使用NodeJS中的事件源构建一个小型应用程序。 Usually I’ve done it in Ruby, doing in NodeJS was interesting and wanted to share

 相关资料
  • Notes App NodeMongo This is a basic App to manage simple Notes on the web using Javascript Technologies like Nodejs, Mongodb, and other related technologies. This app can do: CRUD Operations: create/r

  • 我有一个使用NodeJS、MongoDB(Mongoose作为驱动程序)和ExpressJS的完整web应用程序。 这个项目在我的本地机器上运行得很好。今天我决定把一切都转移到生产上。我正在使用Google App Engine来托管我的应用程序,并使用Compose(形式上是MongoHQ)来托管我的数据库。 App Engine完美地服务于我的应用程序,尽管我的API似乎不起作用。我的API由

  • 我一直在研究App Engine和Cloud SQL。 最近我禁用了数据库的公共访问。此后,我无法使用我的应用引擎连接到CloudSQL(应用引擎和CloudSQL都在同一个Google云项目中)。 我能够连接的唯一方式是在CloudSQL上将应用引擎IP列入白名单。但在新的部署中,IP会发生变化,因此添加静态IP并不是理想的解决方案。 在云SQL连接选项卡中,它显示以下内容: 应用引擎授权< b

  • 问题内容: 我有一个使用NodeJS,MongoDB(以Mongoose作为驱动程序)和ExpressJS的完整Web应用程序。 该项目可以在我的本地计算机上完美运行。今天,我决定将一切都投入生产。我正在使用Google App Engine托管我的应用程序,并使用Compose(以前是MongoHQ)托管我的数据库。 尽管我的API似乎不起作用,但App Engine可以完美地为我的应用程序提供

  • 我知道这个问题已经问过几次了,但我还没有找到一个可行的解决方案。我试图在Heroku上部署我的节点服务器,并且构建成功,但是日志打印出以下消息。我也在使用mongoose,在本地部署也没有问题。 2019-02-10T22:30:10.287542+00:00 Heroku[router]:at=error code=h10 desc=“应用程序崩溃”method=get path=“/favic

  • 我想检查蒙哥数据库中是否已存在电子邮件ID。如果设置了 req.body.email,它将触发MongoDB查询,如果结果为真,则它应该在json中发送状态:true。 我已经尝试从外部发送res.json()User.findOne()仍然不起作用。我已经将接受标头设置为应用程序/json。仍然不起作用。 NodeJS上的代码 前端代码 错误日志