Skip to main content

Overview

Devark supports both JavaScript and TypeScript for all modules. When you add a module to your project, Devark prompts you to choose your preferred language and generates the appropriate files with correct dependencies.

When to Choose JavaScript

JavaScript is ideal when you want to move quickly without type annotations. Perfect for:
  • Small projects or MVPs
  • Simple APIs without complex data structures
  • Teams without TypeScript experience
  • Projects where build speed is critical
JavaScript projects require:
  • No tsconfig.json configuration
  • No TypeScript compiler setup
  • Fewer development dependencies
  • No type definition packages (@types/*)

When to Choose TypeScript

TypeScript provides compile-time type checking and enhanced IntelliSense:
  • Catch errors before runtime
  • Better autocompletion in editors
  • Refactoring with confidence
  • Self-documenting code through types
TypeScript excels in:
  • Projects with multiple developers
  • Complex business logic
  • Long-term maintenance
  • Integration with typed libraries

How Language Selection Works

When you install any Devark module, you’ll see this prompt:
? Which version do you want to add for this module?
  > JavaScript
    TypeScript
Devark then:
  1. Detects or prompts for entry file
    • JavaScript: app.js (root directory)
    • TypeScript: src/app.ts (inside src/ folder)
  2. Installs language-specific dependencies
    • JavaScript: Only runtime dependencies
    • TypeScript: Adds typescript, ts-node, and @types/* packages
  3. Generates files with correct extensions
    • JavaScript: .js files in root directory
    • TypeScript: .ts files in src/ directory
Devark auto-detects TypeScript entry files by searching for .ts files in the src/ directory if your specified entry file isn’t found.

File Structure Differences

my-project/
├── app.js                    # Entry point
├── config/
│   └── googleStrategy.js
├── routes/
│   └── googleAuthRoutes.js
├── controllers/
│   └── otp.js
├── middleware/
│   └── ratelimit.js
├── .env
├── .gitignore
└── package.json
All generated files live in the root directory alongside your entry file.

Code Generation Examples

Devark generates language-appropriate code for each module. Here’s how the same Google OAuth strategy looks in both languages:
import passport from 'passport'
import { Strategy as GoogleStrategy } from 'passport-google-oauth20'

passport.use(new GoogleStrategy({
  clientID: process.env.GOOGLE_CLIENT_ID,
  clientSecret: process.env.GOOGLE_CLIENT_SECRET,
  callbackURL: '/auth/google/callback',
}, (accessToken, refreshToken, profile, done) => {
  // Replace this with DB logic
  return done(null, profile)
}))

passport.serializeUser((user, done) => {
  done(null, user)
})

passport.deserializeUser((user, done) => {
  done(null, user)
})
Notice how TypeScript version includes:
  • Type annotations for all parameters
  • Interface definitions (IUser)
  • Explicit return types
  • Non-null assertions (!) for environment variables

Dependency Differences

Devark automatically installs the correct dependencies based on your language choice:
Runtime dependencies only:
{
  "dependencies": {
    "express": "^4.18.0",
    "passport": "^0.6.0",
    "passport-google-oauth20": "^2.0.0",
    "express-session": "^1.17.0",
    "dotenv": "^16.0.0"
  }
}

Migration Guide

Starting with JavaScript

If you’re unsure which to choose, start with JavaScript:
  1. Install modules with JavaScript option
  2. Build your features quickly
  3. Migrate to TypeScript later if needed

Migrating to TypeScript

When you’re ready to adopt TypeScript:
1

Install TypeScript dependencies

npm install --save-dev typescript ts-node @types/node @types/express
2

Create tsconfig.json

{
  "compilerOptions": {
    "target": "ES2020",
    "module": "commonjs",
    "lib": ["ES2020"],
    "outDir": "./dist",
    "rootDir": "./src",
    "strict": true,
    "esModuleInterop": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true
  },
  "include": ["src/**/*"],
  "exclude": ["node_modules"]
}
3

Create src/ directory

mkdir src
4

Rename files incrementally

Start with your entry file:
mv app.js src/app.ts
Then gradually rename other files:
mv routes/googleAuthRoutes.js src/routes/googleAuthRoutes.ts
mv config/googleStrategy.js src/config/googleStrategy.ts
5

Add type annotations

Update files with TypeScript syntax as you encounter type errors.
6

Re-install modules in TypeScript

For any new modules, choose TypeScript when prompted by Devark.
You can run JavaScript and TypeScript side-by-side during migration. TypeScript can import JavaScript files without issues.

Best Practices

JavaScript Projects

  • Keep files organized in folders (routes, controllers, config)
  • Use JSDoc comments for basic type hints
  • Leverage ES6+ features
  • Consider migrating to TS as project grows

TypeScript Projects

  • Enable strict mode in tsconfig.json
  • Define interfaces for API responses
  • Use enums for constants
  • Leverage utility types (Partial, Pick, Omit)

Source Code Reference

Devark’s language selection logic is implemented in:
  • src/modules/*/install.js - Module installation with language prompts (lines 36-47)
  • src/utils/packageManager.js - Dependency installation logic
  • Template files in templates/javascript/ and templates/typescript/ directories
Devark maintains separate template directories for JavaScript and TypeScript versions of every module, ensuring you always get properly typed code.

Build docs developers (and LLMs) love