<?xml version="1.0" encoding="utf-8" ?><rss version="2.0" xmlns:tt="http://teletype.in/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:media="http://search.yahoo.com/mrss/"><channel><title>Mkots</title><generator>teletype.in</generator><description><![CDATA[This blog is my English homework if you notice any mistake, please  write a comment where is it and I'll correct it]]></description><image><url>https://teletype.in/files/cc/cc76f065-4d3a-462b-8c26-ef7186a251a1.jpeg</url><title>Mkots</title><link>https://teletype.in/@mkots</link></image><link>https://teletype.in/@mkots?utm_source=teletype&amp;utm_medium=feed_rss&amp;utm_campaign=mkots</link><atom:link rel="self" type="application/rss+xml" href="https://teletype.in/rss/mkots?offset=0"></atom:link><atom:link rel="next" type="application/rss+xml" href="https://teletype.in/rss/mkots?offset=10"></atom:link><atom:link rel="search" type="application/opensearchdescription+xml" title="Teletype" href="https://teletype.in/opensearch.xml"></atom:link><pubDate>Thu, 30 Apr 2026 18:00:19 GMT</pubDate><lastBuildDate>Thu, 30 Apr 2026 18:00:19 GMT</lastBuildDate><item><guid isPermaLink="true">https://teletype.in/@mkots/setting-up-server</guid><link>https://teletype.in/@mkots/setting-up-server?utm_source=teletype&amp;utm_medium=feed_rss&amp;utm_campaign=mkots</link><comments>https://teletype.in/@mkots/setting-up-server?utm_source=teletype&amp;utm_medium=feed_rss&amp;utm_campaign=mkots#comments</comments><dc:creator>mkots</dc:creator><title>Configuring a new server</title><pubDate>Tue, 04 Aug 2020 20:11:57 GMT</pubDate><media:content medium="image" url="https://teletype.in/files/bc/cd/bccd5c4b-e23d-4336-be4b-76bd12b2e090.png"></media:content><category>Misc</category><description><![CDATA[1. Add a new user:]]></description><content:encoded><![CDATA[
  <p>1. Add a new user:</p>
  <pre>adduser username </pre>
  <p>2. Add this user to sudoers group:</p>
  <pre>usermod -aG sudo username</pre>
  <p>3. Switch to this user:</p>
  <pre>su - username</pre>
  <p>4. Open the ssh configuration file:</p>
  <pre>vim /etc/ssh/sshd_config</pre>
  <p>5. In the line <strong>PermitRootLogin yes</strong> replace the word <strong>Yes </strong>with the word <strong>No:</strong></p>
  <pre>PermitRootLogin no</pre>
  <p>6. In the line <strong>#PasswordAuthentication yes</strong> replace the word <strong>Yes </strong>with the word <strong>No </strong>and uncomment this line:</p>
  <pre>PasswordAuthentication no</pre>
  <p>7. Add your<strong> id_rsa.pub</strong> to <strong>autorized_keys</strong> (<u>run it from the client</u>):</p>
  <pre>ssh-copy-id username@remote_host</pre>
  <p>8. Save the file and restart the service:</p>
  <pre>sudo service ssh restart</pre>
  <p>9. Install curl:</p>
  <pre>sudo apt update &amp;&amp; sudo apt install curl -y </pre>
  <p>10. Download openvpn-installer:</p>
  <pre>curl -O https://raw.githubusercontent.com/angristan/openvpn-install/master/openvpn-install.sh</pre>
  <p>11. Add execution permission:</p>
  <pre>chmod +x openvpn-install.sh</pre>
  <p>12. Then run it:</p>
  <pre>sudo ./openvpn-install.sh</pre>
  <p>13. Create ssh &quot;bookmark&quot; (<u>run it from the client</u>):</p>
  <pre>echo &quot;Host dev
     HostName 0.0.0.0
     User username
     Port 22
 &quot; &gt;&gt; ~/.ssh/config
</pre>
  <p>14. Copy *.ovpn files to your PC (<u>run it from the client</u>):</p>
  <p><code>scp dev:~/*.ovpn ~/Downloads/</code><br /></p>

]]></content:encoded></item><item><guid isPermaLink="true">https://teletype.in/@mkots/SkPUllEAB</guid><link>https://teletype.in/@mkots/SkPUllEAB?utm_source=teletype&amp;utm_medium=feed_rss&amp;utm_campaign=mkots</link><comments>https://teletype.in/@mkots/SkPUllEAB?utm_source=teletype&amp;utm_medium=feed_rss&amp;utm_campaign=mkots#comments</comments><dc:creator>mkots</dc:creator><title>Create an API via NestJS Part V</title><pubDate>Sun, 15 Dec 2019 17:41:35 GMT</pubDate><media:content medium="image" url="https://teletype.in/files/6e/4f/6e4f7482-a68c-46e4-8b88-b63baaa0e829.png"></media:content><description><![CDATA[<img src="https://teletype.in/files/6e/4f/6e4f7482-a68c-46e4-8b88-b63baaa0e829.png"></img>nest g module user — generate module]]></description><content:encoded><![CDATA[
  <h2>In this part, we&#x27;ll create a User module. </h2>
  <h3>Firstly we have to set up the scaffold</h3>
  <p><code>nest g module user</code> — generate module</p>
  <p><code>nest g controller user</code> — generate controller</p>
  <p>If everything is alright you should see the new folder in your src/. It must contain  files:</p>
  <ol>
    <li>user.controller.spec.ts — tests for controller</li>
    <li>user.controller.ts ­— the controller file (for more information follow the <a href="https://docs.nestjs.com/controllers" target="_blank">link)</a></li>
    <li>user.module.ts — the module file (for more information <a href="https://docs.nestjs.com/modules" target="_blank">link)</a></li>
  </ol>
  <p>After that, we can create the service file </p>
  <p><code>nest g service user/user</code></p>
  <blockquote>This command will create a subfolder in your user folder named user. It quite comfortable for me but if you used to flat project structure you can run this command just: nest g service user/ </blockquote>
  <p>Now let&#x27;s create DTO and Entity files for user module</p>
  <p><code>touch src/user/user.dto.ts<br />touch src/user/user.entity.ts</code><br />Finally, install necessary packages </p>
  <p><code>yarn add jsonwebtoken @types/jsonwebtoken</code></p>
  <p><code>yarn add bcrypt @types/bcrypt</code></p>
  <h3>Let&#x27;s describe the user data model</h3>
  <p>Open user.entity.ts and write something like this:</p>
  <figure class="m_column">
    <img src="https://teletype.in/files/6e/4f/6e4f7482-a68c-46e4-8b88-b63baaa0e829.png" width="2604" />
    <figcaption>user.entity.ts</figcaption>
  </figure>
  <blockquote>Line 12 — declare new entity named &#x27;user&#x27;<br />Line 14-15 — create autogenerated column for user id<br />Line 17-18 — create column to store date user had register <br />Line 20-24 —  the unique column for user id, it needs for decline registration with the same username<br />Line 27-27 — column for password<br />Line 29-32 — function witch called before password could store. This function hashes the user&#x27;s password before we stored it in the database<br />Line 34-41 ­— this function will return UserObject after registration <br />Line 43-53 — getter function for <a href="https://jwt.io/introduction/" target="_blank">JWT token<br /></a>Line 55-57 — password comparator</blockquote>
  <p><u>Not to forget add your SECRET string into .env file, it should be like:</u></p>
  <figure class="m_column">
    <img src="https://teletype.in/files/59/36/5936921f-ae98-4f42-8830-2333668fd176.png" width="1560" />
    <figcaption>.env</figcaption>
  </figure>
  <p>And import it into user.module:</p>
  <figure class="m_column">
    <img src="https://teletype.in/files/84/9b/849b96c1-a8b0-4199-821f-0ab7e0069461.png" width="2468" />
    <figcaption>user.module.ts</figcaption>
  </figure>
  <h3>Describe UserDTO</h3>
  <figure class="m_column">
    <img src="https://teletype.in/files/f1/4b/f14bddca-0383-4b14-ba95-a4b7fb48cef3.png" width="2236" />
    <figcaption>user.dto.ts</figcaption>
  </figure>
  <h3>Create some methods for user module</h3>
  <p>Open the user cntroller and create register, login and get all users command:</p>
  <figure class="m_column">
    <img src="https://teletype.in/files/2d/2e/2d2e99cf-5dc4-45b3-91d8-17ecaf5c6b2b.png" width="3108" />
    <figcaption>user.controller.ts</figcaption>
  </figure>
  <h3>let&#x27;s implement our service methods</h3>
  <p>Firstly you could create dummy functions</p>
  <figure class="m_column">
    <img src="https://teletype.in/files/7f/13/7f1333fb-236d-4738-9c20-5d41efb6b771.png" width="2436" />
    <figcaption>user.service.ts</figcaption>
  </figure>
  <p>Now we can implement getAll() function:</p>
  <figure class="m_column">
    <img src="https://teletype.in/files/1f/14/1f14b3ae-c285-4ffb-8bd9-9685e6e535bf.png" width="2640" />
    <figcaption>user.service.ts</figcaption>
  </figure>
  <blockquote>We use responseObject(false) because we don&#x27;t need to get JWT token in this case</blockquote>
  <p>Next we must implement login() function:</p>
  <figure class="m_column">
    <img src="https://teletype.in/files/79/87/798792d7-30ad-4ba3-9ba3-cf5d1f90bb74.png" width="3280" />
    <figcaption>user.service.ts</figcaption>
  </figure>
  <p>And finnaly implement register() function:</p>
  <figure class="m_column">
    <img src="https://teletype.in/files/a4/72/a4728c9a-4ecf-41c3-93fd-a98bd31f329d.png" width="3312" />
    <figcaption>user.service.ts</figcaption>
  </figure>

]]></content:encoded></item><item><guid isPermaLink="true">https://teletype.in/@mkots/H1x0HJPaB</guid><link>https://teletype.in/@mkots/H1x0HJPaB?utm_source=teletype&amp;utm_medium=feed_rss&amp;utm_campaign=mkots</link><comments>https://teletype.in/@mkots/H1x0HJPaB?utm_source=teletype&amp;utm_medium=feed_rss&amp;utm_campaign=mkots#comments</comments><dc:creator>mkots</dc:creator><title>Create an API via NestJS Part IV</title><pubDate>Thu, 05 Dec 2019 20:17:12 GMT</pubDate><media:content medium="image" url="https://teletype.in/files/8f/8f85e323-3c95-471a-addf-da0d34c46b9f.png"></media:content><category>Create an API via NestJS</category><description><![CDATA[<img src="https://teletype.in/files/8f/8f85e323-3c95-471a-addf-da0d34c46b9f.png"></img>Go to quiz.servise.ts and edit the read() function such as:]]></description><content:encoded><![CDATA[
  <h2>Validation error for CRUD</h2>
  <h3>Create validation function for the Read method</h3>
  <p>Go to <code>quiz.servise.ts</code> and edit the <em>read()</em> function such as:</p>
  <figure class="m_column">
    <img src="https://teletype.in/files/8f/8f85e323-3c95-471a-addf-da0d34c46b9f.png" width="3212" />
    <figcaption>quiz.servise.ts</figcaption>
  </figure>
  <p>Line by line explanation:</p>
  <ol>
    <li>Declaration of the read() function which takes id with string type.</li>
    <li>Writing a response from a database to the quiz constant.</li>
    <li>Checking whether the quiz constant&#x27;s value is &#x27;null&#x27;. The condition will be true if the quiz is undefined or equals to &#x27;null&#x27;.</li>
    <li>Throwing a new exception. It will be handled by our logging interceptor from the previous part. HttpException is the function of two arguments: the first one — a message which will be shown when error threw, second — just server response code like a 404 for Not Found or 200 for OK.</li>
    <li> &quot;Else&quot; statement.</li>
    <li>Returning data that we received from the database.</li>
  </ol>
  <h3>Do the same for Update and Delete methods</h3>
  <figure class="m_column">
    <img src="https://teletype.in/files/c9/c9220bb5-0c80-4295-ab35-7ee6fae91d99.png" width="3212" />
    <figcaption>quiz.servise.ts</figcaption>
  </figure>
  <h3>Create a class validator</h3>
  <p>Install the necessary packages:</p>
  <p><code>yarn add class-transformer class-validator</code></p>
  <p>And create file</p>
  <p><code>touch src/shared/validation.pipe.ts</code></p>
  <p>Now just copy code from the <a href="https://docs.nestjs.com/pipes#class-validator" target="_blank">official documentation,</a> and write some fixes:</p>
  <figure class="m_column">
    <img src="https://teletype.in/files/11/11f57634-f3da-47cc-8314-7692ea86f24f.png" width="3112" />
    <figcaption>validation.pipe.ts</figcaption>
  </figure>
  <blockquote>Rows 14-19 — validate did we receive an empty object.<br />Rows 28-31 ­— pass the errors to logging interceptor.<br />Rows 41-49 — aggregate all errors into one string.<br />Rows 50-56 — a function that checks if an object is empty.</blockquote>
  <p>Then we have to change our DTO file to be able to validate fields:</p>
  <figure class="m_column">
    <img src="https://teletype.in/files/09/0957917d-7c35-4269-a5df-935bb862b49b.png" width="2164" />
    <figcaption>quiz.dto.ts</figcaption>
  </figure>
  <p>Finally, connect your Validation Pipe to the controller:</p>
  <figure class="m_column">
    <img src="https://teletype.in/files/28/28ae63bf-bfd5-44b4-b9d5-842e13dac6db.png" width="2976" />
    <figcaption>quiz.controller.ts</figcaption>
  </figure>

]]></content:encoded></item><item><guid isPermaLink="true">https://teletype.in/@mkots/rkDjfOd2B</guid><link>https://teletype.in/@mkots/rkDjfOd2B?utm_source=teletype&amp;utm_medium=feed_rss&amp;utm_campaign=mkots</link><comments>https://teletype.in/@mkots/rkDjfOd2B?utm_source=teletype&amp;utm_medium=feed_rss&amp;utm_campaign=mkots#comments</comments><dc:creator>mkots</dc:creator><title>Create an API via NestJS Part III</title><pubDate>Sun, 24 Nov 2019 21:14:07 GMT</pubDate><media:content medium="image" url="https://teletype.in/files/e5/e5fc522f-26e5-4b17-a950-fa31b9d85b63.png"></media:content><category>Create an API via NestJS</category><description><![CDATA[<img src="https://teletype.in/files/e5/e5fc522f-26e5-4b17-a950-fa31b9d85b63.png"></img>The next thing that we should do is creating the Logger for our ErrorHandler:]]></description><content:encoded><![CDATA[
  <h2>Create Extended Error handler</h2>
  <ol>
    <li>Create folder:<br /><code>mkdir src/shared &amp;&amp; cd src/shared</code></li>
    <li>Create the filter:<br /><code>touch http-error.filter.ts</code></li>
    <li>Write simple error handler</li>
  </ol>
  <figure class="m_column">
    <img src="https://teletype.in/files/e5/e5fc522f-26e5-4b17-a950-fa31b9d85b63.png" width="3012" />
    <figcaption>src/shared/http-error.filter.ts</figcaption>
  </figure>
  <h2>Include custom error handler as a provider to the app module </h2>
  <figure class="m_column">
    <img src="https://teletype.in/files/77/77e4d85b-e34b-443d-b9c5-577adae6101f.png" width="2772" />
    <figcaption>src/app.module.ts</figcaption>
  </figure>
  <h2>Add a logger to this error handler</h2>
  <p>The next thing that we should do is creating the Logger for our ErrorHandler:</p>
  <p>Open your http-error.filter.ts file and type simple logger:</p>
  <figure class="m_column">
    <img src="https://teletype.in/files/1b/1bd3163a-8027-4711-931f-7b419c32a099.png" width="2268" />
    <figcaption>src/shared/http-error.filter.ts</figcaption>
  </figure>
  <blockquote>Pay attention, this code must be member of catch() function</blockquote>
  <p>Now if we send some incorrect request we should see:</p>
  <figure class="m_column">
    <img src="https://teletype.in/files/d7/d7268544-2463-46cb-852d-88017df67ac8.png" width="4096" />
    <figcaption>console output</figcaption>
  </figure>
  <p>Looks pretty good, but we still don&#x27;t logging crrect requests. </p>
  <h2>Let&#x27;s make <a href="https://docs.nestjs.com/interceptors" target="_blank">interceptor</a></h2>
  <p>Create a new file: <code>touch src/shared/logging.interceptor.ts</code></p>
  <p>And write simple logger:</p>
  <figure class="m_column">
    <img src="https://teletype.in/files/69/69a3f91b-e3ac-4575-93c7-ab445008466d.png" width="3348" />
    <figcaption>src/shared/logging.interceptor.ts</figcaption>
  </figure>
  <p>Now we can connect it as a provider to app.module</p>
  <figure class="m_column">
    <img src="https://teletype.in/files/c2/c2a8e18f-8c30-4884-9604-8960743669c3.png" width="2876" />
    <figcaption>src/app.module.ts</figcaption>
  </figure>
  <p>Check how it works. Start the server and send some correct request, you should get some like this:</p>
  <figure class="m_column">
    <img src="https://teletype.in/files/e8/e8bdcaf7-f0e6-4251-a0b9-dfb9c343d116.png" width="4096" />
  </figure>

]]></content:encoded></item><item><guid isPermaLink="true">https://teletype.in/@mkots/BJ6Tg1NsB</guid><link>https://teletype.in/@mkots/BJ6Tg1NsB?utm_source=teletype&amp;utm_medium=feed_rss&amp;utm_campaign=mkots</link><comments>https://teletype.in/@mkots/BJ6Tg1NsB?utm_source=teletype&amp;utm_medium=feed_rss&amp;utm_campaign=mkots#comments</comments><dc:creator>mkots</dc:creator><title>Create an API via NestJS Part II</title><pubDate>Sat, 09 Nov 2019 06:46:29 GMT</pubDate><media:content medium="image" url="https://teletype.in/files/bb/bb1cfd00-df78-4b49-9270-e72340a1ff10.png"></media:content><category>Create an API via NestJS</category><description><![CDATA[<img src="https://teletype.in/files/bb/bb1cfd00-df78-4b49-9270-e72340a1ff10.png"></img>Via NestCLI generate:]]></description><content:encoded><![CDATA[
  <h2>Create CRUD</h2>
  <h3>Create infrastructure files:</h3>
  <p>Via NestCLI generate:</p>
  <ol>
    <li>Module: <code>nest g mo quiz</code> </li>
    <li>Controller: <code>nest g controller quiz</code></li>
    <li>Service: <code>nest g service quiz/quiz</code></li>
  </ol>
  <blockquote>Where &#x60;quiz&#x60; is the name of your module.</blockquote>
  <h3>Setup API controller</h3>
  <p>1. Open quiz.<strong>controller.ts </strong>and write some CRUD methods:</p>
  <p>You should have something like this</p>
  <figure class="m_column">
    <img src="https://teletype.in/files/bb/bb1cfd00-df78-4b49-9270-e72340a1ff10.png" width="1504" />
    <figcaption>quiz.controller.ts</figcaption>
  </figure>
  <p>2. Open quiz.<strong>module.ts and </strong>import our TypeORM Model:</p>
  <figure class="m_column">
    <img src="https://teletype.in/files/8f/8f01e65c-dc54-42c6-92e6-7ce56e099b73.png" width="1234" />
    <figcaption>quiz.module.ts</figcaption>
  </figure>
  <p>3. Open quiz<strong>.service.ts</strong> and add our Entity Repository:</p>
  <figure class="m_column">
    <img src="https://teletype.in/files/3d/3dcde500-26b0-4d8b-8ee2-e3e95820fd5c.png" width="1234" />
    <figcaption>quiz.service.ts</figcaption>
  </figure>
  <h3>Implement CRUD methods</h3>
  <p>Now we can implement our CRUD methods, that we had been initialized before. Let&#x27;s open quiz.<strong>service.ts</strong> file and write implementation:</p>
  <figure class="m_column">
    <img src="https://teletype.in/files/89/89b508f0-9574-4f2b-963b-e064363f5abd.png" width="2468" />
    <figcaption>quiz.service.ts</figcaption>
  </figure>
  <p>As we can see in lines 16 and 20 we use the  <code>data </code>param with type <code>any</code>. That is not accorded to TypeScript guidelines, we must write DTO (Data Transfer Object) to tipizate this param:</p>
  <h3>Create DTO</h3>
  <p>Firstly we have to create this file via command: <code>touch src/quiz/quiz.<strong>dto.ts</strong></code></p>
  <p>Then open this file and describe our data:</p>
  <figure class="m_column">
    <img src="https://teletype.in/files/4f/4ffd34df-88c2-46b9-a521-c81628df99b7.png" width="796" />
    <figcaption>quiz.dto.ts</figcaption>
  </figure>
  <p>Now we can type param data in quiz<strong>.service.ts:</strong></p>
  <figure class="m_column">
    <img src="https://teletype.in/files/86/86ddf77b-75a4-464e-95d4-62de61d1f0ea.png" width="2504" />
    <figcaption>quiz.service.ts</figcaption>
  </figure>
  <h3>Connect the service to the controller</h3>
  <p>Now, finally, we can connect our service to the controller. Open quiz.<strong>controller.ts</strong> and determinate service functions:</p>
  <figure class="m_column">
    <img src="https://teletype.in/files/35/35d5daee-6bf0-4296-bede-a5f2cef7997e.png" width="2876" />
    <figcaption>quiz.controller.ts</figcaption>
  </figure>
  <p>Finally, you can start your server and test its functionality </p>
  <h3>Test </h3>
  <p>Actually, we must write many tests and mutch documentation for something like Swagger to our API, but not today. In this part, Postman is enough for us. Let&#x27;s install it:</p>
  <pre>sudo snap install postman </pre>
  <p>In the Postman press &quot;New&quot; button: </p>
  <figure class="m_column">
    <img src="https://teletype.in/files/4f/4f4bf8a5-a766-4d21-9bb6-619b215a70b7.png" width="751" />
  </figure>
  <p>On the next step choose &quot;Request&quot;:</p>
  <figure class="m_column">
    <img src="https://teletype.in/files/a6/a6117398-1b26-44a3-8bba-c48c6bd23d7e.png" width="1098" />
  </figure>
  <p>Next, setup Name for request and Name for collection, and press Save to Collection:</p>
  <figure class="m_column">
    <img src="https://teletype.in/files/37/379af54b-a506-4cc5-9e14-21af738d5317.png" width="491" />
  </figure>
  <figure class="m_original">
    <img src="https://teletype.in/files/ad/adc727d3-81dc-4708-9a82-e6384c20aaa4.png" width="497" />
  </figure>
  <figure class="m_column">
    <img src="https://teletype.in/files/08/0803cfa8-5ad2-4221-87b4-496f24b8c550.png" width="483" />
  </figure>
  <h3>GET readAll()</h3>
  <p>Finally, we can create our first request:</p>
  <figure class="m_column">
    <img src="https://teletype.in/files/16/160163da-087a-4f63-a9c0-2c64f0e09262.png" width="1065" />
  </figure>
  <ol>
    <li>Choose type GET</li>
    <li>Write address for entry point with format IP : PORT / service</li>
    <li>Press Send</li>
  </ol>
  <p>If everything is alright, you should see the empty array in the response</p>
  <figure class="m_column">
    <img src="https://teletype.in/files/7e/7e10615f-9428-417a-a327-7f5aa7751549.png" width="425" />
  </figure>
  <h3>POST create()</h3>
  <p>Change Type to POST and create some entry:</p>
  <figure class="m_column">
    <img src="https://teletype.in/files/e5/e5cce03d-a11c-479e-a093-af39e6800c88.png" width="1063" />
  </figure>
  <ol>
    <li>Change Type of Request</li>
    <li>Go to tab &quot;Body&quot;</li>
    <li>Choose &quot;raw&quot; type</li>
    <li>Set &quot;JSON&quot; format</li>
    <li>Write your request data. Fields for body you can find in DTO or Entry files</li>
  </ol>
  <p>Press Send. And you should see a response like this:</p>
  <figure class="m_column">
    <img src="https://teletype.in/files/04/04584115-25d9-4499-a91b-71899355ab8a.png" width="448" />
  </figure>
  <p>Copy id value, it will be necessary for the next request</p>
  <h3>PUT update()</h3>
  <p>Change Type to PUT and edit our entry:</p>
  <figure class="m_column">
    <img src="https://teletype.in/files/47/47837127-7650-44bf-bc36-76fe3b595d05.png" width="1058" />
  </figure>
  <ol>
    <li>Change Type to PUT</li>
    <li>Change URL according to format URL : PORT / SERVICE / UUID </li>
    <li>Edit Body data </li>
  </ol>
  <p>Press Send. Now response will be different:</p>
  <figure class="m_column">
    <img src="https://teletype.in/files/c9/c979b1e5-70a6-45fa-a982-78336902c04a.png" width="452" />
  </figure>
  <h3>DELETE delete()</h3>
  <p>Change type to DELETE</p>
  <figure class="m_column">
    <img src="https://teletype.in/files/6f/6f805e7c-c69b-41bd-9261-839687686879.png" width="1063" />
  </figure>
  <ol>
    <li>Change Type to DELETE and press Send</li>
  </ol>
  <p>The response should be:</p>
  <figure class="m_column">
    <img src="https://teletype.in/files/ea/ea24a48d-0120-4e81-9684-cf8aa776374d.png" width="451" />
  </figure>

]]></content:encoded></item><item><guid isPermaLink="true">https://teletype.in/@mkots/SJ1wGU2qr</guid><link>https://teletype.in/@mkots/SJ1wGU2qr?utm_source=teletype&amp;utm_medium=feed_rss&amp;utm_campaign=mkots</link><comments>https://teletype.in/@mkots/SJ1wGU2qr?utm_source=teletype&amp;utm_medium=feed_rss&amp;utm_campaign=mkots#comments</comments><dc:creator>mkots</dc:creator><title>Create an API via NestJS Part I</title><pubDate>Sun, 03 Nov 2019 14:17:10 GMT</pubDate><media:content medium="image" url="https://teletype.in/files/ef/efbc26dc-2a43-4e6e-b2f7-08bb19553e1a.png"></media:content><category>Create an API via NestJS</category><description><![CDATA[<img src="https://teletype.in/files/ef/efbc26dc-2a43-4e6e-b2f7-08bb19553e1a.png"></img>Firstly we need to install CLI tools for creating the scaffold.]]></description><content:encoded><![CDATA[
  <h2>1. Setup the project</h2>
  <p>Firstly we need to install CLI tools for creating the scaffold.</p>
  <p>I use the npm for this because the yarn has a bug with node engine version:</p>
  <pre>npm i -g @nestjs/cli</pre>
  <p>After that, we must create a new boilerplate project:</p>
  <p><code>nest new {type your project name here}</code></p>
  <p>This wizard will ask you about which package manager is you prefer:</p>
  <pre>Which package manager would you ❤️ to use?
&gt;npm
&gt;yarn</pre>
  <p>I prefer yarn and in this article, I had chosen it.</p>
  <p>When installation will be done you will see:</p>
  <figure class="m_column">
    <img src="https://teletype.in/files/ef/efbc26dc-2a43-4e6e-b2f7-08bb19553e1a.png" width="1582" />
    <figcaption>bash output</figcaption>
  </figure>
  <p>Now we can setting up Prettier:</p>
  <p><code>cd {YourProjectName}<br />vim .prettierrc</code> </p>
  <p>In this file we must wrote something like this:</p>
  <p><code>{<br />  &quot;useTabs&quot;: false,<br />  &quot;tabWidth&quot;: 2,<br />  &quot;singleQuote&quot;: true,<br />  &quot;trailingComma&quot;: &quot;all&quot;,<br />  &quot;semi&quot;: true,<br />  &quot;jsxBracketSameLine&quot;: true,<br />  &quot;bracketSpacing&quot;: true,<br />  &quot;arrowParens&quot;: &quot;avoid&quot;<br />}</code></p>
  <p>Finally we can start project and have see Hello World message, let&#x27;s try:</p>
  <p><code>cd {YourProjectName}</code></p>
  <pre>yarn run start </pre>
  <p>When you will see:</p>
  <figure class="m_column">
    <img src="https://teletype.in/files/9a/9ae9a12a-3fd7-4e70-a42a-06d01be44402.png" width="2020" />
    <figcaption>bash output</figcaption>
  </figure>
  <p>You can check how it&#x27;s work into your browser on page <a href="http://localhost:3000" target="_blank">http://localhost:3000</a></p>
  <p>And now you probably get stuck with :3000, what does it mean? Yeah, it is port of your server, it can be change in <em>src/main.ts</em> file line 6:</p>
  <figure class="m_column">
    <img src="https://teletype.in/files/6c/6c8a6665-bfa3-480b-b8e7-afbcfa715ee5.png" width="1202" />
    <figcaption>src/main.ts</figcaption>
  </figure>
  <p>It&#x27;s not beautiful enough, what we have to do if we&#x27;ll want change it dynamically? Yes, we must pull it into enviroment variable. But how? </p>
  <p>The <em>dotenv </em>packagecomes to our aid, let&#x27;s add it:</p>
  <p><code>yarn add dotenv</code></p>
  <p>and setup it:</p>
  <p><code>touch .env &amp;&amp; echo &quot;PORT=4000&quot; &gt; .env</code></p>
  <p>Now we can use environment variables in our project just like this:</p>
  <figure class="m_column">
    <img src="https://teletype.in/files/f9/f989cbbd-e943-4b51-a84e-d4fe3654ec9f.png" width="1202" />
    <figcaption>src/main.ts</figcaption>
  </figure>
  <p>What is we have done?</p>
  <ol>
    <li>Imported package dotenv/config into main.ts</li>
    <li>Created constant with the value from .env file or, if it&#x27;s empty,  8080</li>
    <li>Used it in the function app.listen() </li>
  </ol>
  <p>Now we can check this, go to <a href="http://localhost:4000" target="_blank">http://localhost:4000</a> if we have done everything right, we&#x27;ll see the &quot;Hello World&quot; message.</p>
  <blockquote>Not forget to reload your server, if you want use hotreload you have to use <u>yarn run start:dev </u>instead of <u>yarn run start </u></blockquote>
  <p>Looks good, but how we can know witch PORT used now? We have to write a Logger for our server! Open <em>main.ts</em> file and add this string after <em>app.listen()</em> function:</p>
  <figure class="m_column">
    <img src="https://teletype.in/files/75/757cd981-d0c5-4665-b0a2-355fd2da348e.png" width="1286" />
    <figcaption>src/main.ts</figcaption>
  </figure>
  <p>Now, after you start your server you must see message like this:</p>
  <figure class="m_column">
    <img src="https://teletype.in/files/99/996a06fe-4432-4a95-8bca-2a114b1d9ec6.png" width="2048" />
    <figcaption>bash output</figcaption>
  </figure>
  <h2>2. Install packages to using DataBase</h2>
  <h3>JS packages</h3>
  <p>In order to work with the database, we need to install some packages:</p>
  <pre>yarn add pg typeorm @nestjs/typeorm</pre>
  <h3>OS packages</h3>
  <p>For development we also need Postgres Server and PgAdmin tool, if you are use Ubuntu 18.04 you have to install it this way:</p>
  <ol>
    <li><code>cd /etc/apt/sources.list.d/</code></li>
    <li><code>sudo touch pgdg.list</code></li>
    <li><code>echo &quot;deb <a href="http://apt.postgresql.org/pub/repos/apt/" target="_blank">http://apt.postgresql.org/pub/repos/apt/</a> bionic-pgdg main&quot; &gt; pgdg.list</code></li>
    <li><code>wget --quiet -O - <a href="https://www.postgresql.org/media/keys/ACCC4CF8.asc" target="_blank">https://www.postgresql.org/media/keys/ACCC4CF8.asc</a> | sudo apt-key add -</code></li>
    <li><code>sudo apt-get update</code></li>
    <li><code>sudo apt install postgresql-11 postgresql-client-11 pgadmin4 </code></li>
  </ol>
  <p>For another OS check <a href="https://www.postgresql.org/download/" target="_blank">this page</a>.</p>
  <h3>After installation instruction:</h3>
  <ol>
    <li>Edit the <code>pg_hba.conf </code>file: <code>sudo vim /etc/postgresql/11/main/pg_hba.conf</code></li>
    <li>Change the line <code>local all postgres peer </code>to<code> local all postgres trust</code></li>
    <li>Restart <code>postgresql</code> service: <code>sudo service postgresql restart</code></li>
    <li>Log in into DB and change password: </li>
    <ol>
      <li><code>psql -U postgres</code></li>
      <li>In the postgres=# prompt: <code>ALTER USER postgres with password ‘new-password’;</code></li>
    </ol>
    <li>Revert the changes:</li>
    <ol>
      <li> <code>sudo vim /etc/postgresql/11/main/pg_hba.conf </code>change line from <code>trust </code>to <code>md5</code></li>
      <li>Restart <code>postgresql</code> service: <code>sudo service postgresql restart</code></li>
    </ol>
  </ol>
  <h2>3. Setup DataBase</h2>
  <h3>Create a new DataBase </h3>
  <ol>
    <ul></ul>
    <li>Login to Postgres</li>
    <ul>
      <li><code>psql -U postgres</code></li>
    </ul>
    <li>Create a new DB</li>
    <ul>
      <li><code>create database quiz;</code></li>
      <li><code>\q</code>  - to quit from psql</li>
    </ul>
  </ol>
  <h3>Connect the DataBase to your project</h3>
  <ol>
    <ol></ol>
  </ol>
  <p>Create ORM config file</p>
  <ul>
    <ul>
      <li><code>touch ormconfig.js</code></li>
      <li>Edit this file as follows </li>
    </ul>
  </ul>
  <figure class="m_column">
    <img src="https://teletype.in/files/bc/bcbaee86-ce89-49b7-9912-bc8f65330b90.png" width="1572" />
    <figcaption><code>ormconfig.js</code></figcaption>
  </figure>
  <blockquote>Where fields &quot;host&quot;, &quot;username&quot;, &quot;password&quot;, &quot;database&quot; is your credentials to database which can set in .env file  </blockquote>
  <ul>
    <ul>
      <li>Set credentials in .env file:</li>
    </ul>
  </ul>
  <figure class="m_column">
    <img src="https://teletype.in/files/d6/d6f8813f-e2ee-41e0-95f1-c43b2b48652e.png" width="796" />
    <figcaption>.en</figcaption>
  </figure>
  <p>Import ORM module:</p>
  <ul>
    <ul>
      <li>Go to file <code>src/app.module.ts</code></li>
      <li>Add the following lines:</li>
    </ul>
  </ul>
  <figure class="m_column">
    <img src="https://teletype.in/files/78/7825a894-1649-4031-9034-74793d69d9bd.png" width="1184" />
    <figcaption>src/app.module.ts</figcaption>
  </figure>
  <h2>Start working with DB</h2>
  <h3>Create entities</h3>
  <ol>
    <li>Create entnities structure</li>
    <ul>
      <li><code>mkdir src/quiz</code></li>
      <li><code>cd src/quiz/ &amp;&amp; touch quiz.entity.ts</code></li>
    </ul>
    <li>Edit <code>quiz.entity.ts </code>as follow:</li>
    <ol></ol>
  </ol>
  <figure class="m_column">
    <img src="https://teletype.in/files/4c/4cad6e3f-5e87-47f7-9086-9997a36d92c4.png" width="1118" />
  </figure>
  <h3>Check if it work</h3>
  <p>Star your server via <code>yarn run start </code>. Then you must see output like that:</p>
  <figure class="m_column">
    <img src="https://teletype.in/files/5a/5a058c7d-3d6f-4189-8751-f9b3766e91f6.png" width="2048" />
    <figcaption>bash output</figcaption>
  </figure>
  <p>Now browse the DB:</p>
  <ul>
    <ul>
      <li><code>psql -U postgres - connect to db server</code></li>
      <li><code>\c quiz - open db called quiz</code></li>
      <li><code>\dt - describe tables within</code></li>
    </ul>
  </ul>
  <p>If everything is ok, you should see: </p>
  <figure class="m_column">
    <img src="https://teletype.in/files/d4/d49fdc29-aa3e-4dd0-ae3c-7e44e4ea6d1f.png" width="932" />
    <figcaption>bash output</figcaption>
  </figure>

]]></content:encoded></item><item><guid isPermaLink="true">https://teletype.in/@mkots/wordpress-in-docker</guid><link>https://teletype.in/@mkots/wordpress-in-docker?utm_source=teletype&amp;utm_medium=feed_rss&amp;utm_campaign=mkots</link><comments>https://teletype.in/@mkots/wordpress-in-docker?utm_source=teletype&amp;utm_medium=feed_rss&amp;utm_campaign=mkots#comments</comments><dc:creator>mkots</dc:creator><title>Wordpress in Docker</title><pubDate>Fri, 13 Jul 2018 15:07:56 GMT</pubDate><media:content medium="image" url="https://teletype.in/files/b4/64/b4646739-c405-4a24-b17b-746e8d0a6fc4.jpeg"></media:content><category>Misc</category><description><![CDATA[<img src="https://teletype.in/files/ff/ff418c77-9349-4286-b1fe-1b073d052db5.png"></img>Возможно, потребуется установка curl]]></description><content:encoded><![CDATA[
  <ol>
    <li>Скачать Docker-compose</li>
  </ol>
  <pre>sudo curl -L https://github.com/docker/compose/releases/download/1.21.2/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose</pre>
  <p>Возможно, потребуется установка <code>curl</code></p>
  <pre>sudo apt install curl
</pre>
  <p>2. Дать права на исполнение</p>
  <pre>sudo chmod +x /usr/local/bin/docker-compose
</pre>
  <p>3. Протестировать</p>
  <pre>docker-compose --version
</pre>
  <p>4. Создать папку под проект и перейти в нее</p>
  <pre>sudo mkdir ~/wordpress &amp;&amp; cd ~/wordpress
</pre>
  <p>5. Создать файл <code>docker-compose.yml</code> и добавить в него конфиг</p>
  <pre>sudo nano docker-compose.yml


version: &#x27;3.3&#x27;

services:
   db:
     image: mysql:5.7
     volumes:
       - db_data:/var/lib/mysql
     restart: always
     environment:
       MYSQL_ROOT_PASSWORD: somewordpress
       MYSQL_DATABASE: wordpress
       MYSQL_USER: wordpress
       MYSQL_PASSWORD: wordpress

   wordpress:
     depends_on:
       - db
     image: wordpress:latest
     ports:
       - &quot;8000:80&quot;
     restart: always
     environment:
       WORDPRESS_DB_HOST: db:3306
       WORDPRESS_DB_USER: wordpress
       WORDPRESS_DB_PASSWORD: wordpress
volumes:
    db_data:
</pre>
  <p>6. Собрать и поднять контейнер</p>
  <pre>sudo docker-compose up -d
</pre>
  <p>7. Установить Wordpress</p>
  <p>Перейти на http://127.0.0.1:8000</p>
  <figure class="m_custom">
    <img src="https://teletype.in/files/ff/ff418c77-9349-4286-b1fe-1b073d052db5.png" width="504" />
  </figure>

]]></content:encoded></item></channel></rss>