Skip to content

abnerfs/ts-node-init

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 

Repository files navigation

TypeScript With ts-node-dev

Sample commands to init a NodeJS TypeScript project

Dependencies

yarn add typescript ts-node ts-node-dev @types/node --dev

OR

npm i typescript ts-node ts-node-dev @types/node --save-dev

tsconfig.json

Create tsconfig.json in the root directory that will contain your typescript compiler configuration, more information in https://www.typescriptlang.org/docs/handbook/tsconfig-json.html

{
  "compilerOptions": {
    "target": "es2017", 
    "experimentalDecorators": true, 
    "emitDecoratorMetadata": true, 
    "module": "commonjs",
    "rootDir": "./src", 
    "outDir": "./dist", 
    "removeComments": true, 
    "esModuleInterop": true, 
    "forceConsistentCasingInFileNames": true, 
    "strict": true, 
    "resolveJsonModule": true,
    "skipLibCheck": true 
  }
}

According to our configuration you should write your code in src/ folder and should have an entry point file called index.ts inside.

image

package.json

Add dev and build scripts to your package.json file,

"scripts": {
    "build": "tsc",
    "dev": "ts-node-dev --respawn --transpile-only --ignore-watch node_modules --no-notify src/index.ts"
  }

NPM Package

If you are writing a npm package specify main and types path and add --declaration to your build script in order to generate types suggestions to who is using your package.

package.json

"main" : "dist/index.js",
"types" : "dist/index.d.ts",
"scripts": {
    "build": "tsc --declaration"
  }

Run

npm run dev

OR

yarn dev

Build

npm run build

or

yarn build

Releases

No releases published

Packages

No packages published
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy