- Notifications
You must be signed in to change notification settings - Fork16
Commands to init NodeJS + TypeScript projects
License
abnerfs/ts-node-init
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Sample commands to init a NodeJS TypeScript project
yarn add typescript ts-node ts-node-dev @types/node --devOR
npm i typescript ts-node ts-node-dev @types/node --save-devCreatetsconfig.json in the root directory that will contain your typescript compiler configuration, more information inhttps://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 insrc/ folder and should have an entry point file calledindex.ts inside.
Adddev andbuild scripts to yourpackage.json file,
- Dev: Usests-node-dev to start a dev server that automatically transpiles your.ts files to.js whenever you edit something. (More info athttps://www.npmjs.com/package/ts-node-dev)
- Build: Usestsc to transpile your whole application to.js, is used when you want to deploy to production. (More info athttps://www.typescriptlang.org/docs/handbook/compiler-options.html)
"scripts": {"build":"tsc","dev":"ts-node-dev --respawn --transpile-only --ignore-watch node_modules --no-notify src/index.ts" }
If you are writing a npm package specifymain andtypes 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" }
npm run devOR
yarn devnpm run buildor
yarn buildAbout
Commands to init NodeJS + TypeScript projects
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
