Posts

Showing posts from 2020

Hãy sử dụng ESLint cho dự án của bạn!

Bài viết gốc: https://manhhomienbienthuy.bitbucket.io/2018/May/20/we-should-use-eslint-in-project.html (đã xin phép tác giả ) JavaScript đã trở thành một ngôn ngữ cực kỳ phổ biến trong lập trình web. Gần như bất cứ lập trình viên web nào cũng đều phải biết code JavaScript. Thế nhưng biết là một chuyện, code tốt lại là chuyện khác. Trong bài viết này, tôi sẽ giới thiệu một công cụ giúp chúng ta code JavaScript tốt hơn, đó chính là ESLint. Mở đầu Hiện nay JavaScript đã có những phát triển rất xa so với những thế hệ ban đầu, khi mà những đặc tả ES2015 (ECMAScript 2015 - ES6) và ES2017 được công bố. Đặc biệt, rất nhiều thư viện của JavaScript như ReactJS , AngularJS , VueJS , v.v... giúp chúng ta có thể xây dựng những ứng dụng web cực kỳ cool. Mặc dù có những đặc tả kỹ thuật như vậy, nhưng việc code JavaScript hiện nay vẫn còn rất nhiều vấn đề. Vì vậy, việc đảm bảo chất lượng của code JavaScript vẫn luôn là một thách thức lớn. Có rất nhiều yếu tốt để tạo ra một project ...

Deploy Node.js App with GitLab CI/CD

https://medium.com/@seulkiro/deploy-node-js-app-with-gitlab-ci-cd-214d12bfeeb5

Continuous Integration with Node.js, Heroku and GitLab CI/CD -Part 2.

Image
In the last part , we able to set up our git repository on GitLab set up our Node app with Express and write one unit test. In this part, we’ll cover the following: Setup of the app on Heroku GitLab CI/CD configuration using the .gitlab-ci.yml file GitLab repository:- https://gitlab.com/Mjeck/node-heroku-gitlab That done next is to create our app on Heroku. If you don’t have an account yet navigate to https://heroku.com and create a free account. With that done log on to your Heroku dashboard and create a new app. Create a new app on Heroku. Next, we go to our project directory in our code editor and create a new file and .gitlab-ci.yml paste the following code. # Node docker image on which this would be run image: node:8.10.0 cache: paths: - node_modules/ stages: - test - deploy_production # Job 1: Test: stage: test script: - npm install - npm run test # Job 2: # Deploy to staging Production: image: ruby:latest only: - ma...

Continuous Integration with Node.js, Heroku and GitLab CI/CD -Part 1.

Image
https://hocweb.vn/deploy-app-nodejs-voi-gitlab-ci-cd/ https://medium.com/@McDave95/continuous-integration-with-node-js-heroku-and-gitlab-ci-cd-part-1-1fe93a1d5967 CI/CD can be a mess at times, especially for newbies. The stress of having to use products you aren’t familiar with. But with GitLab’s integrated CI/CD feature it takes most of the hassle away. What we’ll achieve: Setup a node server with the express npm package Setup GitLab CI/CD Write Unit Test Deploy app on Heroku Prerequisites: A GitLab account Little understanding of Node.js Git and Node installed on your system Favourite Editor of choice ( ….visual studio code) GitLab repository:- https://gitlab.com/Mjeck/node-heroku-gitlab So our app would just take in two inputs, adds them together and returns the answer. Not so much you might say. Dependencies: express: — for handling our web server body-parser: — Node.js body parsing middleware. mocha: — test framework to run...

Tổng quan về PM2

Image
Mình vừa trở về sau khi tham gia chuyển đổi hệ thống cho một dự án. Ban đầu dự án này xây dựng dựa trên nền tảng duy nhất là PHP 5.5 build trên một VPS tại Singapore. Là thành viên trong bất kỳ dự án nào, mình luôn mong muốn đem lại những trải nghiệm tốt nhất tới người sử dụng, một khi họ truy cập vào website. Và các thành viên trong team đều ý thức được rằng đó là một trong những yếu tố quan trọng ảnh hưởng tới tỉ lệ giữ chân người dùng. Do đó hệ thống sẽ phải có những thay đổi, đặc biệt là tốc độ tải trang phải nhanh và ổn định trong khi dự án sẽ ngày một phình to hơn. Đó là lý do Nodejs được lựa chọn và áp dụng. Tại sao sử dụng PM2? Khi mới cài đặt, chưa có một tool nào được tích hợp để phục vụ cho deployment cho nodejs app. Và đó thực sự là vấn đề cần được giải quyết ngay. Khi bạn chạy một Nodejs app, tức là đang tạo ra một process mới (tiến trình mới) trên server. Chúng ta cần một trình quản lý process với nhiều yêu cầu được đặt ra: Ổn định, tin cậy để giữ ser...

Các framework Node.js phổ biến

Image
Giới thiệu JavaScript chỉ là một ngôn ngữ lập trình phía client chạy trên trình duyệt, phải không? Nhưng điều này không còn đúng chút nào nữa. Node.js là một cách để chạy JavaScript trên server nhưng nó còn hơn thế nữa. Với Node.js, nó đã tìm ra cách có thể chạy ở phía server, do đó giảm sự phức tạp của việc sử dụng hai ngôn ngữ khác nhau ở cả hai đầu. Ngày nay Node.js cung cấp một trong những giải pháp tiên tiến nhất để xây dựng các ứng dụng web / di động. Phạm vi sử dụng của nó đang được gia tăng nhanh chóng với sự đóng góp tích cực từ cộng đồng phát triển và các công ty công nghệ khổng lồ khác. Các framework đã mở rộng các chức năng của Node.js đến một mức độ đáng kể và cũng đã xây dựng các tính năng mới hơn, tiện ích, dễ sử dụng và thông minh hơn. Ngày nay, các framework như Express.js và Hapi.js đang nổi lên và trở thành một trong những nền tảng cho việc xây dựng các trang web và ứng dụng di động tốt hơn và nhanh hơn. Do đó hôm nay mình sẽ giới thiệu một số frame...

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 ...