Automatically translated.View original post

PM2. In the ubuntu server???

# Trending # Drug sign with lemon8 # webserver # Web Site Writing Basics

PM2 (Process Manager 2) is the process manager for Node.js (but also supports other languages) most popular on Linux Server like Ubuntu. To explain it simply, PM2 is the "app administrator" who keeps your app running 24 / 7, even if you have closed the terminal screen, or even when the Server is rebuilt. How does PM2 work? The principle of PM2 has four key things: 1. Background Process (Daemon) Normally, if you run the app with the node app.js command, when you close the terminal window, the app will die immediately, but PM2 will turn the app into a Background Service, making the app always run behind it 2.Auto Restart (Watch & Restart) If your app "Crash" or Error goes off, PM2 will detect it immediately and automatically restore the app within a second. 3. Cluster Mode (Power Expansion) This is a great feature. PM2 can command your apps to run multiple Instances based on the amount of CPU Core you have to help prevent the impact of many users without having to write any more code. 4. Startup ScriptPM2 can create a script for itself to run when Ubuntu turns on (Boot), making sure that if the power goes out, your website or API will come back online without typing the command to run the frequently used command in Ubuntu, the command to describe pm2, start app.js, start running the application2, list all apps running and state (CPU / RAM used) pm2, stop < id / name >, pm2, restart < id / name >, restart (often after editing the code) pm2, logs, Log, Work or Error that happens Real-metipm2, beautiful Dashboard screen For a detailed pm2 state, the startup creates a command for running on automatic power-up. In a nutshell, if you do the web with Node.js on Ubuntu and want it to be "persistent and online all the time," you need to use PM2.

1/30 Edited to

... Read moreถ้าคุณกำลังค้นหาแนว ๆ “endpointbasecamp” แล้วมาเจอโพสต์นี้ บางทีคุณอาจกำลังทำ API/endpoint บน Ubuntu Server แล้วอยากให้ระบบมัน “นิ่ง” และออนไลน์ตลอด (ไม่หลุดเวลา SSH หลุด หรือเครื่องรีบูต) — ตรงนี้ PM2 ช่วยได้มากครับ ผมสรุปเป็นแนวทางใช้งานจริงที่เจอบ่อย ๆ เวลาเอา endpoint ขึ้นเซิร์ฟเวอร์ 1) ติดตั้ง PM2 ให้เรียบร้อยก่อน ส่วนใหญ่ผมติดตั้งผ่าน npm แบบ global: - npm i -g pm2 จากนั้นเช็กว่าใช้งานได้ด้วย pm2 -v 2) เริ่มรันแอปให้ถูกแบบ Production ถ้าแอปคุณมีไฟล์เริ่มต้นเช่น app.js หรือ index.js ให้เริ่มด้วย: - pm2 start app.js --name api-endpoint ตั้งชื่อไว้จะสั่งง่ายขึ้นมาก (แทนการจำ id) 3) เช็กสถานะเหมือนในภาพเทอร์มินัลที่หลายคนคุ้น คำสั่งที่ผมใช้แทบทุกวัน: - pm2 list (ดูว่า online / stopped พร้อม CPU และ RAM) - pm2 stop api-endpoint - pm2 restart api-endpoint เวลามีอัปเดตโค้ดแล้วอยากให้ endpoint รีโหลดเร็ว ๆ ก็ restart ได้เลย 4) ดู error และ log เพื่อไล่ปัญหา endpoint ตอบช้า/ล่ม - pm2 logs api-endpoint ช่วยมากตอน endpoint มี error เฉพาะบางเคส หรือมี request หนัก ๆ แล้วค้าง ถ้าอยากดูภาพรวมแบบเรียลไทม์: - pm2 monit 5) ทำให้รันอัตโนมัติหลัง reboot (สำคัญมากสำหรับงานจริง) อันนี้คือจุดที่ทำให้ server ดู “มืออาชีพ” ขึ้นทันที: - pm2 startup มันจะโชว์คำสั่งอีกบรรทัดให้เรา copy ไปรันต่อ (ตาม systemd ของเครื่อง) จากนั้นอย่าลืมบันทึกรายการโปรเซส: - pm2 save ทีนี้ต่อให้เครื่องดับ/รีสตาร์ต endpoint ของคุณก็กลับมา online เอง 6) ทริคเล็ก ๆ สำหรับงาน endpoint/API ที่คนเรียกเยอะ ถ้าเครื่องมีหลายคอร์และต้องการรับโหลดมากขึ้น สามารถใช้ cluster mode: - pm2 start app.js -i max --name api-endpoint มันจะสร้างหลาย instance ตามจำนวนคอร์ ช่วยกระจายโหลดได้โดยไม่ต้องแก้โค้ดเยอะ โดยรวมถ้าคุณกำลังทำเว็บหรือ API (endpoint) บน Ubuntu Server แล้วอยากให้บริการเสถียร PM2 คือเครื่องมือที่คุ้มที่สุดตัวหนึ่งครับ: สั่ง start/list/stop ได้ง่าย เห็นสถานะ online ชัดเจน มี logs ให้ไล่ปัญหา และตั้ง startup ให้บูตติดเองได้จริง

Related posts

Happy Tuesday Texas ! #junkjournalwithme #journaltok #journalcommunity #fyp #asmrsounds
_cozypaper

_cozypaper

25 likes

a weekend away means a new journal spread is coming🤭 #junkjournal #pittsburgh #crafty #scrapbooking #memories
taylordharrish

taylordharrish

7 likes

Account for sale rare old
Pubg_Store

Pubg_Store

1 like

Ubuntu 25.04 beta preview
#productivity #ergonomy #motivation #linux #ubuntu
Eric Nantel

Eric Nantel

2 likes

November is going to be a movieee ! Upcoming events - @Dallas Haitians United (DHU) Gala Event November 8th @The African Think Tank is hosting the UBUNTU Gala on November 15th Check out my stories to book your tickets ❤️ #ubuntugala2025 #thingstodoindallas #dallasliving #dalla
itsdonnyanegera

itsdonnyanegera

2 likes

Mi vida siendo maquilladora y mesera en Miami🩷✨
#gettoknowme #miamimakeup #serverlife #makeupartist
Orianna Cardozo

Orianna Cardozo

0 likes

Scary Server
Made this with clear resin, alcohol inks, and gel window clings.... Going to auction this off Monday, October 20, 2025 at 2:30pm Follow me to make sure you get the updates.... #halloween #party #resinart #originalart #bloody
internal

internal

0 likes

week 2 of junk journaling
day 8: carryout from Fusian 🍣🥢 day 9: vintage junk 🌚 day 10: more vintage junk 🌸 day 11: my cats 🐈🐈‍⬛️ day 12: walgreens 💊 day 13: groceries ft. osky🥫 day 14: oil change 🚘🛢 #junkjournaling #journal #art #crafts #scrapbook
becca ⛄️

becca ⛄️

116 likes

A hand holds a homemade bagel sandwich filled with lettuce, tomato, cheese, and deli meat. The bagel is topped with sesame and poppy seeds, ready to be enjoyed.
Ingredients for making bagels are displayed on a white surface, including flour, instant yeast, salt, water, sugar, and an egg.
Four raw bagel dough rings are shown boiling in a pot of water, a key step in preparing homemade bagels.
#bagels 🥯 #homemadebagels
Baking Ubuntu 🇿🇦X🇺🇸

Baking Ubuntu 🇿🇦X🇺🇸

0 likes

[ Nobody Knows What Just Happened ]
let me know if you rocking with the vid. Follow me on all my socials ! Twitch: https://www.twitch.tv/wauln Facebook: https://www.facebook.com/Wauln YouTube: https://www.youtube.com/@wauln Stream Highlights: https://www.youtube.com/@waulnsworld Kick: https://www.kick.com/wauln
Wauln

Wauln

0 likes

Server life
#server #serverstruggles B.A.N.A.N.A.S
Shelby Paige

Shelby Paige

66 likes

Burrito bowl
Kingstree First time making a “ chipotle “bowl , I’m impressed 🤤
Baking Ubuntu 🇿🇦X🇺🇸

Baking Ubuntu 🇿🇦X🇺🇸

3 likes

Shinny Magmortar Minecraft Pixelmon Complex Server
New stream Posted up today got this bad mutha flower #pokemon #minecraft #shorts #gaming #newstreamer
OfficialJRoy23

OfficialJRoy23

1 like

Join my brand new server! PUFFSSTRONG HOLD
https://discord.gg/wsHsedJr https://discord.gg/wsHsedJr👍Pros: https://discord.gg/wsHsedJr 🤔Cons:pints and dead 🛍Brand:pvz / gaming Random Thoughts
King puff💯💯💯

King puff💯💯💯

0 likes

An advertisement for the 'AhRust Midlife' Rust console server, featuring a person in a hazmat suit sitting on a toilet. The image highlights server details like 'SERVER ID: D695D2B', 'ALL ADULTS', and 'RAID WEEKENDS', with the text 'SOMETIMES AGE ISN'T THE CRISIS'.
RUST CONSOLE SERVER
CONSOLE. Crisis is still playing the game at the children's table.... needing other adults to play with. Finding a server with no bull 💩, no beta behaviors/toxicity. Grab a cold adult beverage, snacks, put your feet up and come sit/hang with the adults at the adult table. Fresh new w
PaisleyRain

PaisleyRain

1 like

My new game cups coming soon!
#robloxgaming #newgame #speed #flash
3amwastaken

3amwastaken

0 likes

Make a few orders with me! #smallbusiness #businessowner #dayinmylife #frozenflamingo #frozencustard
Faith Thomas 🦩

Faith Thomas 🦩

31 likes

Server Tip Tracker
Super cute digital or printable Tip Tracker to keep servers or bartenders organized! Link in my bio! Grab yours today and start staying on top of your tips! I use mine daily! #server #bartender #waitress #servertips #money
Serverchronicles

Serverchronicles

3 likes

See more