Get Started: Install Node and Run Your First Script
Goal of this page
You will create a minimal Node.js project that is TypeScript-first, runnable locally, and structured in a way that will not collapse once the codebase grows. We keep tooling light, but we do not ignore production realities.
Install Node.js (LTS recommended)
Use an LTS version for backend work. LTS reduces surprises and is the default choice for production deployments. Verify your installation:
node -v npm -v
Create a project folder
mkdir my-node-app cd my-node-app npm init -y
TypeScript-first dependencies
We need TypeScript itself, Node type definitions, and a dev runner. We use tsx for a simple “run TS directly” workflow in development.
npm i -D typescript tsx @types/node
Create tsconfig
Create a TypeScript config. Keep it simple at the start, then tighten later.
npx tsc --init
Recommended minimal scripts
Add scripts to package.json so the whole team runs the same commands. Example:
{
"scripts": {
"dev": "tsx watch src/index.ts",
"build": "tsc -p tsconfig.json",
"start": "node dist/index.js"
}
}
Create the entry file
Create src/index.ts:
console.log('Node + TypeScript is ready');
Run in development
npm run dev
Build and run like production
In production you should run compiled JavaScript. Build then run:
npm run build npm start
Folder structure that scales
Start with a clean layout. Even small projects benefit from a predictable structure:
src/ index.ts app/ modules/ shared/ tests/ package.json tsconfig.json
Environment variables
Do not hardcode secrets or environment-specific values. Use environment variables. A simple example:
const port = Number(process.env.PORT ?? 3000);
console.log('Port:', port);
Common beginner mistake: mixing dev and prod execution
Running TypeScript directly in production is usually the wrong move. Dev runners are for development speed. Production expects stable, built artifacts.
JS note
In JavaScript-only projects you can skip TypeScript and run node src/index.js. But for backend systems, TypeScript usually pays for itself quickly through safer refactors and fewer runtime mistakes.
Production habits from day one
- Use scripts (
dev/build/start) so the workflow is consistent. - Prefer LTS for production systems.
- Separate source (
src) from build output (dist). - Use environment variables for config.
Next steps
Next we will cover requirements and version strategy (LTS, npm, OS notes), then the differences between Node and browser JavaScript, and finally the V8 runtime basics.