DEV Community

Pacharapol Withayasakpunt
Pacharapol Withayasakpunt

Posted on

`node index.js` which variations do you use?

Also, do you use non-pure version in production? What about NPM library publishing?

Top comments (4)

thecodepixi profile image
Emmy | Pixi

This is a fun question. It really depends on what I'm working on. If I'm doing something in plain JS without an dependencies (rare) it's easy enough to just node index.js. When I'm working on an Express server I add a script to my package.json called dev that starts up nodemon, so I can just yarn dev and leave the server up while I work on it.

patarapolw profile image
Pacharapol Withayasakpunt • Edited

Personally, I am a TypeScript user, so I use both ts-node, ts-node-dev in development. And, node in production.

TypeScript is already Babel-like with additional features, and can transpile down to Node12, Node10 or Node8, so this tsconfig.json should be safe enough.

  "compilerOptions": {
    "target": "esnext",  // This should be OK for Node 12
    // For Node 10 -- ES2018, correct me if I am wrong
    "module": "commonjs",
    // Will be ESNext, if you transpile for Rollup or Deno
    "alwaysStrict": true,
    // You don't have to write `"use strict";`, but it will be emitted
    "experimentalDecorators": true,
    // This will correctly transpile, even without Babel
    "emitDecoratorMetadata": true
    // If you use this, you might also need `reflect-metadata`

Recently, I have problems with absolute imports, but I practically fixed it.

patarapolw profile image
Pacharapol Withayasakpunt

That is, if in package.json is "main": "index.js".

itsjzt profile image
Saurabh Sharma

Its usually

ts-node-dev src/index.ts

in development