Posts

Showing posts from May, 2020

Advanced Node.js Project Structure Tutorial

Project structuring is an important topic because the way you bootstrap your application can determine the whole development experience throughout the life of the project. In this Node.js project structure tutorial I’ll answer some of the most common questions we receive at RisingStack about structuring advanced Node applications, and help you with structuring a complex project. These are the goals that we are aiming for: Writing an application that is easy to scale and maintain. The config is well separated from the business logic. Our application can consist of multiple process types. Node.js at Scale is a collection of articles focusing on the needs of companies with bigger Node.js installations and advanced Node developers. Chapters: Click to see all chapters of Node.js at Scale: Using npm npm Tricks and Best Practices SemVer and Module Publishing Understanding the Module System, CommonJS and require Node.js Internals Deep Dive The Node.js Even...

The 5 fundamental rules of a Node.js Project Structure

There are a lot of possible ways to organize a Node.js project - and each of the known methods has their ups and downs. However, according to our experience, developers always want to achieve the same things: clean code and the possibility of adding new features with ease. In the past years at RisingStack, we had a chance to build efficient Node applications in many sizes, and we gained numerous insights regarding the dos and donts of project structuring. We have outlined five simple guiding rules which we enforce during Node.js development. If you manage to follow them, your projects will be fine: Rule 1 - Organize your Files Around Features, Not Roles Imagine, that you have the following directory structure: // DON'T . ├── controllers | ├── product.js | └── user.js ├── models | ├── product.js | └── user.js ├── views | ├── product.hbs | └── user.hbs The problems with this approach are: to understand how the product pages work, you have to open up ...

7 Quy tắc cấu trúc ứng dụng Node.js

Image
Node.js đã rất nhanh chóng bắt kịp các ngôn ngữ Java, Python, Ruby, .Net,...  để trở thành 1 trong những sự lựa chọn cho công việc lập trình ứng dụng web. Đội Node.js đã làm cho JavaScript runtime trở nên tốt hơn, nhanh hơn, đẹp hơn qua từng ngày. Cộng đồng của nó cũng ngày 1 phát triển. Với sự tăng trưởng đó, ngày càng nhiều các developer nhảy vào công nghệ mới mẻ này, đối mặt với cùng vấn đề và code những tính năng tương tự nhau. Vì lý do đó, cộng đồng Node.js đã tạo ra các framework và các design pattern để "giúp đỡ" các lập trình viên, không chỉ giúp họ giải quyết các vấn đề thường gặp mà còn giúp cấu trúc ứng dụng Node.js. Các framework thông thường sẽ implement MV pattern như MVC (Model-View-Controller),  MVVM (Model-View-ViewModel), MVP (Model-View-Presenter) hay chỉ đơn giản là MV (Model-View). Các pattern kể trên giúp cấu trúc code, cho biết phần code model, hay view, hay controller, nằm ở đâu; vị trí phần code cho nhiệm vụ route; code cấu hì...

Using a Database (with Mongoose)

Image
https://developer.mozilla.org/en-US/docs/Learn/Server-side/Express_Nodejs/mongoose This article briefly introduces databases, and how to use them with Node/Express apps. It then goes on to show how we can use Mongoose to provide database access for the LocalLibrary website. It explains how object schema and models are declared, the main field types, and basic validation. It also briefly shows a few of the main ways in which you can access model data. Prerequisites: Express Tutorial Part 2: Creating a skeleton website Objective: To be able to design and create your own models using Mongoose. Overview Library staff will use the Local Library website to store information about books and borrowers, while library members will use it to browse and search for books, find out whether there are any copies available, and then reserve or borrow them. In order to store and retrieve information efficiently, we will store it in a database . Express apps...