Setting Up Node.js with Parcel and TypeScript

September, 19th 2024 2 min read

How to Set Up a Node.js Project with Parcel and TypeScript

If you’re looking to streamline your Node.js development workflow, combining Parcel with TypeScript gives you fast bundling, zero-config builds, and powerful type safety. This guide walks you through creating a clean project setup that’s ready for efficient development.

Step 1: Initialize Your Node.js Project

Create a new directory:

plaintext
mkdir parsel-ts && cd parsel-ts

Initialize npm:

plaintext
npm init -y

A fresh package.json is now created.

Step 2: Install Parcel Bundler

Parcel is a zero-config bundler, ideal for rapid development.

Install Parcel:

plaintext
npm install -D parcel parcel-bundler

Step 3: Set Up TypeScript

Install TypeScript and Node.js types:

plaintext
npm install -D typescript @types/node

Initialize a TypeScript configuration:

plaintext
npx tsc --init

Update tsconfig.json:

json
{
  "compilerOptions": {
    "target": "es6",
    "module": "commonjs",
    "strict": true,
    "esModuleInterop": true
  },
  "include": ["src/**/*"]
}

Step 4: Create Source Files

Create a src directory:

plaintext
mkdir src

Add src/index.ts:

ts
console.log("Parcel + TypeScript project is running!");

Step 5: Configure Parcel Entry Point

Parcel works automatically with TypeScript.

Add scripts to package.json:

json
"scripts": {
  "dev": "parcel src/index.ts",
  "build": "parcel build src/index.ts"
}

If using HTML entry points, swap in src/index.html.

Step 6: Run the Development Server

Start dev mode:

plaintext
npm run dev

Parcel will watch changes and rebuild instantly.

Build for production:

plaintext
npm run build

Conclusion

You now have a clean, modern Node.js workflow powered by Parcel and TypeScript. Parcel handles fast bundling with zero config, while TypeScript provides type safety and maintainability. This setup is perfect for modern backend tools, scripts, or small full-stack apps.