{"id":70,"date":"2022-02-25T07:47:46","date_gmt":"2022-02-25T07:47:46","guid":{"rendered":"https:\/\/im8bit.com\/?p=70"},"modified":"2022-03-21T17:08:59","modified_gmt":"2022-03-21T17:08:59","slug":"nodejstypescript-project-quickstart","status":"publish","type":"post","link":"https:\/\/im8bit.com\/?p=70","title":{"rendered":"NodeJS+Typescript Project Quickstart"},"content":{"rendered":"\n<p>1. Step one, create a directory for your project<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mkdir PROJECT_NAME &amp;&amp; cd PROJECT_NAME<\/code><\/pre>\n\n\n\n<p>2. Init your project (using yarn in this case)<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>yarn init<\/code><\/pre>\n\n\n\n<p>3. Add typescript to the project<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>yarn add typescript --dev<\/code><\/pre>\n\n\n\n<p>4. Init Typescript (create tsconfig.json, this one has a lot of options but this will get you started)<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>yarn tsc --init --rootDir src --outDir dist<\/code><\/pre>\n\n\n\n<p>5. Create the folder for the src code<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mkdir src &amp;&amp; cd src<\/code><\/pre>\n\n\n\n<p>6. Create the file <strong>app.ts<\/strong> with your favorite editor and add<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>console.log(\"Hello Typescript!\")<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Two Options From Here<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>You can either compile to JS and run<\/strong>:<\/h3>\n\n\n\n<p>7a. Compile to JS (remember to run this one from your the project folder not from source:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>yarn tsc<\/code><\/pre>\n\n\n\n<p>8a. And run!<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>node dist\/app.js<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Or  you can also skip the compile to js part:<\/strong><\/h3>\n\n\n\n<p>7b. Add ts-node to your project<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>yarn add ts-node --dev<\/code><\/pre>\n\n\n\n<p>8b. and run from the typescript source without compiling to js:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>yarn ts-node src\/app.ts <\/code><\/pre>\n\n\n\n<p>Have fun!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1. Step one, create a directory for your project 2. Init your project (using yarn in this case) 3. Add typescript to the project 4. Init Typescript (create tsconfig.json, this one has a lot of options but this will get you started) 5. Create the folder for the src code 6. Create the file app.ts &#8230; <a class=\"read-more\" href=\"https:\/\/im8bit.com\/?p=70\">Read More<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-70","post","type-post","status-publish","format-standard","hentry","category-blog"],"_links":{"self":[{"href":"https:\/\/im8bit.com\/index.php?rest_route=\/wp\/v2\/posts\/70","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/im8bit.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/im8bit.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/im8bit.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/im8bit.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=70"}],"version-history":[{"count":11,"href":"https:\/\/im8bit.com\/index.php?rest_route=\/wp\/v2\/posts\/70\/revisions"}],"predecessor-version":[{"id":103,"href":"https:\/\/im8bit.com\/index.php?rest_route=\/wp\/v2\/posts\/70\/revisions\/103"}],"wp:attachment":[{"href":"https:\/\/im8bit.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=70"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/im8bit.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=70"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/im8bit.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=70"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}