Best AWS EC2 Instance for Node.js
For most Node.js services — REST APIs, server-rendered React/Next, microservices — **t4g.medium** is the cost-effective sweet spot at $0.0336/hr (~$24/mo). Two vCPUs and 4GB of RAM gives you enough headroom to run PM2 in cluster mode (two worker processes), a local memory cache, and a comfortable V8 heap without paging.
Node.js is one of the workloads where ARM64 (Graviton) genuinely wins. V8 has had first-class ARM64 support since Node 18, npm packages with native modules have shipped arm64 prebuilds for years (sharp, bcrypt, node-canvas, etc.), and the price/performance is meaningfully better than the Intel sibling. The cost savings vs t3.medium are real — typically 20% per hour, which compounds across a fleet.
The burstable model works particularly well for Node.js APIs because each request is event-loop-bound and short. CPU credits replenish during the idle gaps between requests. The pattern breaks down for two specific cases: server-side React rendering with large component trees (each render is CPU-pegged for tens of milliseconds), and image processing with sharp or canvas operations. For both, switch to c-series sustained-CPU instances.
One gotcha specific to Node.js: V8's heap can grow surprisingly large with connection pools, ORM caches, and any in-process caching layer. If you're running a Node service with ~4GB of expected heap, give yourself an 8GB instance — running close to the heap limit triggers GC pauses that look like latency spikes you can't easily explain. The t4g.large is often the right step up purely for memory headroom rather than CPU.
Alternatives by tier
Things to consider
- Node.js is single-threaded per process — running PM2 cluster mode with N processes (where N = number of vCPUs) is usually optimal
- Native modules (sharp, bcrypt, node-canvas, anything with prebuilt binaries) need ARM64 versions — most popular packages ship them, but verify
- For CPU-heavy operations (image processing with sharp, SSR with React), the event loop blocks — sustained CPU instances avoid the burstable credit trap
- Memory matters more than vCPUs for many Node workloads — V8 heap can grow surprisingly large with caches and connection pools