LogoDuyệtSr. Data Engineer
HomeAboutPhotosInsightsCV

Footer

Logo

Resources

  • Rust Tiếng Việt
  • /archives
  • /series
  • /tags
  • Status

me@duyet.net

  • About
  • LinkedIn
  • Resume
  • Projects

© 2026 duyet.net | Sr. Data Engineer | 2026-02-27

Nodejs - Tạo static server đơn giản với Nodejs

Note: This post is over 11 years old. The information may be outdated.

English version: https://blog.duyet.net/2015/08/nodejs-create-simple-static-server-with.html

Note: This tutorial uses the static-html-server package. For modern alternatives in 2025, consider using npx http-server, Vite preview mode, or other lightweight server solutions.

Cài đặt

$ npm install static-html-server -g

Tạo thư mục chứa các file html, css

Mình tạo 1 thư mục project, đường dẫn ~/project/test-static-server với 2 file bên trong

  • index.html
  • style.css

Khởi động Server

Khởi động server bằng lệnh:

$ static-html-server -p 8888 -r ~/project/test-static-server

Với

  • -p 8888 là port của server .
  • -r ~/project/test-static-server là đường dẫn đến thư mục gốc của project.

Mở trình duyệt và truy cập http://localhost:8888

Chúc các bạn thành công.

Alternatives for 2025

If you're looking for modern alternatives, here are some options:

  • npx http-server - Quick and simple static server (no installation needed)
  • npx vite --host - Modern build tool with preview mode
  • Built-in Node.js modules - Use http module directly
  • npx live-server - Adds live reload to static files

Github Project

Github repo: https://github.com/duyet/static-html-server

Issues: https://github.com/duyet/static-html-server/issues

Aug 9, 2015·11 years ago
|Javascript|
Node.jsTutorial
|Edit|

Related Posts

Resting và Spreading JavaScript Objects

Resting và spreading càng ngày được ưa chuộng vì sự tiện lợi của nó, sau đây là 7 tricks với JavaScript objects.

Mar 27, 2019·7 years ago
Read more

Cách sử dụng Destructuring trong Javascript ES6

Destructuring là chức năng mới trong ES6 của Javascript. Giúp extract dữ liệu (có thể lồng nhau) từ Array hoặc Object.

May 27, 2016·10 years ago
Read more

Deploy production Node.js với PM2 và Nginx

Cách cài đặt và triển khai production Node.js project với Nginx và PM2.

Apr 10, 2016·10 years ago
Read more

Nodejs - Mã hóa mật khẩu

Mã hóa mật khẩu người dùng trước khi lưu vào database là 1 chuyện bắt buộc phải làm đối với bất cứ 1 website nào. Không riêng gì ai, Nodejs cũng hỗ trợ khá nhiều thư viện để hỗ trợ việc mã hóa này.

Feb 3, 2016·10 years ago
Read more
On this page
  • Cài đặt
  • Tạo thư mục chứa các file html, css
  • Khởi động Server
  • Alternatives for 2025
  • Github Project
On this page
  • Cài đặt
  • Tạo thư mục chứa các file html, css
  • Khởi động Server
  • Alternatives for 2025
  • Github Project