Node.jsExpressError Fix2026 Updated

Node.js Server Not Starting— Complete Fix Guide 2026

January 20267 min readNode.js · All OS

⚡ Run These Checks First

# 1. Check for syntax errors (no execution)
node --check server.js

# 2. Install missing packages
npm install

# 3. Run with full error output
node --stack-trace-limit=100 server.js

The error message will tell you exactly what is wrong. Still stuck? Every fix is below.

Diagnose in 60 Seconds — Read the Error

Node.js server not starting is always caused by one of eight specific problems. The error message in your terminal identifies which one. Match your error below and jump to the right fix:

Error Message → Cause → Fix

Error contains...CauseFix
SyntaxError: Unexpected tokenSyntax error in your JS codeJump →
Cannot find moduleMissing npm package or wrong pathJump →
EADDRINUSE: address already in usePort is occupied by another processJump →
ENOENT: no such fileWrong entry file name or pathJump →
process.env.X is undefinedMissing .env file or dotenv not calledJump →
node: command not foundNode.js not installed or not in PATHJump →
Starts then exits immediatelyUnhandled error crashing the processJump →
No output at allSilent failure — need verbose modeJump →
1

Syntax Error in Your Code

SyntaxError: Unexpected token
2 min

A syntax error prevents Node.js from even parsing your file. The error shows the exact file and line number.

Terminal Error
SyntaxError: Unexpected token '}'
    at wrapSafe (node:internal/modules/cjs/loader:1383:18)
    at Module._compile (node:internal/modules/cjs/loader:1412:20)
    at /Users/you/projects/app/server.js:42

Check syntax without executing the file

terminal
node --check server.js
# Output example:
# /path/to/server.js:42
#   const app = express()
#               ^
# SyntaxError: Unexpected token

Common syntax mistakes

common errors
// Missing closing brace
app.get('/api', (req, res) => {
  res.json({ data: 'hello' })
// ← missing }

// Missing comma in object
const config = {
  host: 'localhost'   // ← missing comma
  port: 3000
}

// Unclosed string
const message = 'Hello world
// ← missing closing quote

// Wrong async/await
app.get('/api', async (req, res) => {
  const data = fetchData()  // ← missing await
})

Use VS Code or any modern editor — it highlights syntax errors with red underlines in real time before you even run the file.

2

Missing npm Packages

Cannot find module 'express'
2 min
terminal
# Install all packages from package.json
npm install

# If you just cloned a repo — always run this first
npm install

# Reinstall if node_modules is corrupted
rm -rf node_modules package-lock.json
npm install

After any git clone, always run npm install before trying to start the server. node_modules is never committed to git.

3

Port Already in Use

EADDRINUSE: address already in use :::3000
1 min
terminal
# macOS / Linux
kill -9 $(lsof -ti:3000)

# Windows
netstat -ano | findstr :3000
taskkill /PID <PID> /F

# Then restart
npm start

See the full article on Node.js port already in use for all scenarios.

4

Wrong Entry File Name or Path

ENOENT: no such file or directory
1 min
terminal
# Check what files exist
ls *.js
# server.js? index.js? app.js?

# Check main field in package.json
cat package.json | grep main

# Run the correct file
node server.js
node index.js
node app.js
node src/index.js

Check your package.json scripts section — the start script shows the exact file name: 'start': 'node server.js'. Make sure that file exists.

5

Missing Environment Variables

undefined env vars / .env not loaded
2 min
server.js — add to line 1
require('dotenv').config()  // must be FIRST line

const express = require('express')
// Now process.env.PORT, process.env.DATABASE_URL etc. are available

Check .env file exists in project root

terminal
ls -la | grep .env
# Should show: .env

# If missing — create it
touch .env
# Then add your variables:
# PORT=3000
# DATABASE_URL=mongodb://localhost:27017/mydb

Debug which variables are loaded

server.js — temporary debug
const result = require('dotenv').config()
console.log('dotenv loaded:', result.parsed)
console.log('PORT:', process.env.PORT)
6

node Command Not Found

node: command not found
5 min
terminal
# Install Node.js via nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/install.sh | bash
source ~/.zshrc
nvm install --lts
nvm use --lts

# Verify
node --version
npm --version
7

App Starts Then Immediately Stops

Process exits right after starting
3 min

The server starts but exits in under a second. This is an unhandled error crashing the process. The crash is silent unless you add error handlers.

Add crash catchers to see the real error

server.js — add at very top
// Add these FIRST to catch all errors
process.on('uncaughtException', (err) => {
  console.error('UNCAUGHT EXCEPTION:', err)
  console.error(err.stack)
})

process.on('unhandledRejection', (reason, promise) => {
  console.error('UNHANDLED REJECTION at:', promise)
  console.error('Reason:', reason)
})

Common causes of immediate crash

  • Database connection failing at startup — app crashes before server starts listening
  • Required environment variable is undefined and used immediately
  • Importing a file that throws an error when loaded
  • Calling an async function without awaiting at the top level

Wrap database connections in try/catch

server.js — safe startup pattern
async function startServer() {
  try {
    // Connect to database first
    await mongoose.connect(process.env.MONGODB_URI)
    console.log('Database connected')

    // Only start server after DB is ready
    app.listen(3000, () => {
      console.log('Server running on port 3000')
    })
  } catch (err) {
    console.error('Failed to start server:', err)
    process.exit(1)
  }
}

startServer()
8

Run With Full Debug Output

No output — silent failure
1 min

If you see absolutely nothing — no error, no output — Node.js is failing silently. These commands extract the maximum possible detail:

terminal
# Maximum stack trace depth
node --stack-trace-limit=50 server.js

# Enable all debug logs
NODE_DEBUG=* node server.js

# Specific debug modules
NODE_DEBUG=net,http node server.js

# Use the Chrome debugger
node --inspect server.js
# Then open: chrome://inspect in Chrome browser

# Check Node.js version compatibility
node --version

How to Prevent Node.js Not Starting

Complete Diagnosis Checklist

  1. 1

    Run node --check server.js

    Finds syntax errors without executing

  2. 2

    Run npm install

    Fixes missing module errors

  3. 3

    Kill the port: kill -9 $(lsof -ti:3000)

    Fixes EADDRINUSE

  4. 4

    Check file name: ls *.js

    Ensures entry file exists

  5. 5

    Check .env exists: ls -la | grep .env

    Fixes missing env variables

  6. 6

    Add uncaughtException handler

    Reveals silent crash cause

  7. 7

    Run node --stack-trace-limit=100 server.js

    Maximum error detail

Frequently Asked Questions

Why is my Node.js server not starting?+
The most common causes are: syntax error in your code (run node --check server.js), missing npm packages (run npm install), port already in use (kill the port), or wrong entry file path. Read the full error message — it tells you exactly what is wrong.
Node.js app starts then immediately stops — why?+
An unhandled error is crashing the process right after start. Run node server.js directly (not nodemon) to see the full error message. Add process.on('uncaughtException', console.error) temporarily to catch hidden errors.
How do I debug a Node.js server that won't start?+
Run: node --stack-trace-limit=100 server.js for maximum error detail. Or: node --inspect server.js then open Chrome and go to chrome://inspect for the full debugger.
Node.js server not starting after npm install?+
Check for a .env file if your app requires environment variables (add require('dotenv').config() and create .env). Run node --check server.js to find any syntax errors. Verify the correct entry file name.
How do I check if my Node.js syntax is correct?+
Run: node --check server.js. This validates syntax without executing the file. It will print the exact line number of any syntax error.
Node.js starts locally but not on the server — why?+
Different environment variables, different Node.js version, missing node_modules (run npm install on the server), wrong start command, or insufficient memory. Check server logs and ensure your deployment runs npm install before starting.

Need Expert Help?

We Build Production-Grade Node.js Apps

Softplix is a full-stack development agency. Dealing with complex Node.js startup issues in production? We can audit your app and fix it.

Talk to an Engineer