{"id":299915,"date":"2020-03-10T15:00:17","date_gmt":"2020-03-10T15:00:17","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=299915"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=299915","title":{"rendered":"\u0421\u043e\u0437\u0434\u0430\u0435\u043c CRUD API \u043d\u0430 Express \u0438 MySQL: \u0447\u0430\u0441\u0442\u044c \u0432\u0442\u043e\u0440\u0430\u044f"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/company\/otus\/blog\/491786\/\"><i><b>\u0412\u0441\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442. \u0412 \u043f\u0440\u0435\u0434\u0434\u0432\u0435\u0440\u0438\u0438 \u0441\u0442\u0430\u0440\u0442\u0430 \u043a\u0443\u0440\u0441\u0430 <a href=\"https:\/\/otus.pw\/3iFx\/\">\u00ab\u0420\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a Node.js\u00bb<\/a>, \u0445\u043e\u0442\u0438\u043c \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435\u043c <a href=\"https:\/\/habr.com\/ru\/company\/otus\/blog\/491408\/\">\u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0430<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u044b\u043b \u043d\u0430\u043f\u0438\u0441\u0430\u043d \u043d\u0430\u0448\u0438\u043c \u0432\u043d\u0435\u0448\u0442\u0430\u0442\u043d\u044b\u043c \u0430\u0432\u0442\u043e\u0440\u043e\u043c.<\/b><\/i><\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/ly\/hi\/h2\/lyhih2n_wa-5o-ot-lsa-ly7wgy.png\">  <\/p>\n<hr>\n<p>  \u0412\u0441\u0435\u043c \u0435\u0449\u0435 \u0440\u0430\u0437 \u043f\u0440\u0438\u0432\u0435\u0442. \u041c\u044b \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u0441\u044f \u043a \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0430 Node.js \u0438 MySQL \u0434\u043b\u044f \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e todo \u2014 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0430 Node.js \u0434\u043b\u044f React. \u0421 \u043f\u0440\u043e\u0448\u043b\u043e\u0433\u043e \u0440\u0430\u0437\u0430 \u044f \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u0435\u0440\u0435\u0441\u043c\u043e\u0442\u0440\u0435\u043b \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0438 \u0442\u0435\u043f\u0435\u0440\u044c \u0440\u0435\u0448\u0438\u043b \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u043a\u043e\u043b\u043e\u043d\u043a\u0443 \u0432 \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e\u0434 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c <code>inner_key<\/code>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u0430 \u043d\u0430\u043c \u0434\u043b\u044f \u043e\u0442\u0440\u0438\u0441\u043e\u0432\u043a\u0438 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0445 \u043a\u043b\u044e\u0447\u0435\u0439 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0434\u0435\u043b\u0430 (\u0432 \u0441\u043f\u0438\u0441\u043a\u0435 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u044e\u0449\u0438\u0445\u0441\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 React \u043d\u0443\u0436\u0435\u043d \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u043a\u043b\u044e\u0447 \u043d\u0430 \u043a\u0430\u0436\u0434\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0434\u043b\u044f \u0435\u0433\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0432 Virtual DOM. \u0415\u0441\u043b\u0438 \u044d\u0442\u043e \u043f\u043e \u043f\u0440\u0435\u0436\u043d\u0435\u043c\u0443 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u0443 \u0432\u0430\u0441 \u0432\u043e\u043f\u0440\u043e\u0441\u044b, \u0432\u0430\u043c \u0441\u0442\u043e\u0438\u0442 \u0438\u0437\u0443\u0447\u0438\u0442\u044c <a href=\"https:\/\/ru.reactjs.org\/docs\/lists-and-keys.html\">\u044d\u0442\u0443 \u0441\u0442\u0430\u0442\u044c\u044e<\/a>).<\/p>\n<p>  <a name=\"habracut\"><\/a><\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/yp\/sh\/qe\/ypshqew81mzi4zodmrbvkmsbigq.png\"><br \/>  \u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043a\u043e\u043b\u043e\u043d\u043a\u0443 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0432 MySQL:<\/p>\n<pre><code class=\"sql\">  ALTER TABlE TODO ADD inner_key varchar(100); <\/code><\/pre>\n<p>  \u0414\u0430, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043d\u0435 \u0441\u0442\u043e\u0438\u0442 <code>timestamp<\/code> (\u0430 \u0438\u043c\u0435\u043d\u043d\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>Date.now()<\/code> \u044f \u0441\u043e\u0437\u0434\u0430\u044e \u043a\u043b\u044e\u0447\u0438 \u0434\u043b\u044f \u0441\u0432\u043e\u0435\u0433\u043e \u0434\u0435\u043b\u0430 \u0432 React) \u0441\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0442\u044c \u0432 \u043a\u043e\u043b\u043e\u043d\u043a\u0443 <code>varchar<\/code>, \u043d\u043e \u044f \u043d\u0430\u0434\u0435\u044e\u0441\u044c, \u0447\u0442\u043e \u044d\u0442\u043e \u043d\u0435\u0441\u043b\u043e\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043f\u0440\u0430\u0432\u0438\u0442\u044c, \u0435\u0441\u043b\u0438 \u043a\u0442\u043e-\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u043d\u0438\u043c\u0430\u0442\u044c\u0441\u044f \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0435\u0439 \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u0421 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u044f \u043d\u0435 \u0441\u043e\u0431\u0438\u0440\u0430\u044e\u0441\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c timestamp \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c \u0432 \u043c\u043e\u0435\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438, \u043c\u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435. \u0422\u0430\u043a \u0447\u0442\u043e \u043f\u043e\u043a\u0430 \u044d\u0442\u043e \u043d\u0435 \u043d\u0435\u0441\u0435\u0442 \u043d\u0438\u043a\u0430\u043a\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b.<\/p>\n<h4> \u041d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u0435 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0432 \u0440\u0430\u0431\u043e\u0442\u0435 \u043d\u0430\u0448\u0435\u0439 \u043c\u043e\u0434\u0435\u043b\u0438<\/h4>\n<p>  \u0414\u0430\u043b\u044c\u0448\u0435, \u0432 \u0441\u0432\u044f\u0437\u0438 \u0441 \u044d\u0442\u0438\u043c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f\u043c\u0438, \u0443 \u043d\u0430\u0441 \u043f\u043e\u043c\u0435\u043d\u044f\u043b\u0430\u0441\u044c \u0438 \u0441\u0430\u043c\u0430 \u043c\u043e\u0434\u0435\u043b\u044c \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. <br \/>  \u0422\u0435\u043f\u0435\u0440\u044c \u0443 \u043d\u0430\u0441 \u043f\u043e-\u0434\u0440\u0443\u0433\u043e\u043c\u0443 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u0432 \u043d\u0430\u0447\u0430\u043b\u0435 \u043d\u0430\u0448\u0435\u0439 \u043c\u043e\u0434\u0435\u043b\u0438, \u0443 \u043d\u0435\u0433\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u043e\u0441\u044c \u043d\u043e\u0432\u043e\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e:<\/p>\n<pre><code class=\"javascript\">const Deal = function(deal) {   this.text = deal.text;   this.inner_key = deal.inner_key; };  <\/code><\/pre>\n<p>  \u041e\u043f\u0435\u0440\u0430\u0446\u0438\u044e \u043f\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044e \u0434\u0435\u043b\u0430 \u0432 \u041c\u043e\u0434\u0435\u043b\u0438 \u044f \u0438\u0437\u043c\u0435\u043d\u0438\u043b \u0447\u0438\u0441\u0442\u043e \u043a\u043e\u0441\u043c\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u0438. \u0410 \u0432\u043e\u0442 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u043f\u043e \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044e \u0434\u0435\u043b\u0430 \u043f\u043e <code>id<\/code> \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0441\u0438\u043b\u044c\u043d\u043e \u043f\u043e\u043c\u0435\u043d\u044f\u0442\u044c, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043c\u044b \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0434\u0435\u043b\u043e \u043f\u043e <code>inner_key<\/code>. \u0415\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435, \u044f \u043d\u0435 \u0441\u0442\u0430\u043b \u043c\u0435\u043d\u044f\u0442\u044c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b <code>res dealId<\/code>, \u043d\u043e \u0432 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435, \u044d\u0442\u043e \u043d\u0435 \u0441\u0438\u043b\u044c\u043d\u043e \u0440\u0435\u0436\u0435\u0442 \u0447\u0438\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043a\u043e\u0434\u0430:<\/p>\n<pre><code class=\"plaintext\">Deal.findById = (dealId, result) =&gt; {   sql.query(`SELECT * FROM TODO WHERE inner_key = '${dealId}'`, (err, res) =&gt; {  \t\/\/ \u0437\u0434\u0435\u0441\u044c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043e\u0448\u0438\u0431\u043e\u043a, \u043d\u0435 \u0432\u0438\u0436\u0443 \u0441\u043c\u044b\u0441\u043b\u0430 \u0435\u0435 \u0434\u0443\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c      if (res.length) {       console.log(&quot;\u043d\u0430\u0439\u0434\u0435\u043d\u043e \u0434\u0435\u043b\u043e: &quot;, res[0]);       result(null, res[0]);       return;     }     \/\/ \u0435\u0441\u043b\u0438 \u0432\u0434\u0440\u0443\u0433 \u043d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u043d\u0430\u0439\u0442\u0438     result({ kind: &quot;not_found&quot; }, null);   }); }; <\/code><\/pre>\n<p>  \u041a\u0440\u043e\u043c\u0435 \u043d\u0435\u0433\u043e, \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043c\u0443\u0442\u0430\u0446\u0438\u0438 \u043f\u043e\u0434\u0432\u0435\u0440\u0433\u0441\u044f \u0438 \u0437\u0430\u043f\u0440\u043e\u0441 \u0432\u0441\u0435\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u0442\u0430\u0431\u043b\u0438\u0446\u044b. \u0414\u043b\u044f \u043c\u043e\u0435\u0433\u043e React \u2014 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0435 \u043d\u0443\u0436\u043d\u044b <code>id<\/code> \u0438\u0437 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445, \u043c\u043d\u0435 \u043d\u0443\u0436\u0435\u043d <code>inner_key<\/code>. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u043e\u043c\u0435\u043d\u044f\u043b\u0441\u044f \u0438 \u0441\u0430\u043c \u0437\u0430\u043f\u0440\u043e\u0441:<\/p>\n<pre><code class=\"javascript\">Deal.getAll = result =&gt; {    const queryAll = &quot;SELECT text, inner_key FROM TODO&quot;;   sql.query(queryAll, (err, res) =&gt; { \/\/ \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043e\u0448\u0438\u0431\u043e\u043a <\/code><\/pre>\n<p>  \u0412 \u043c\u0435\u0442\u043e\u0434\u0435 <i>update <\/i>\u043c\u044b \u0442\u043e\u0436\u0435 \u0442\u0435\u043f\u0435\u0440\u044c \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u043c \u0434\u0435\u043b\u043e \u043f\u043e <code>innerkey<\/code>, \u0438 \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0438 \u0432 \u043c\u0435\u0442\u043e\u0434\u0435 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f:<\/p>\n<pre><code class=\"javascript\">Deal.updateById = (inner_key, deal, result) =&gt; {   const queryUpdate = &quot;UPDATE TODO SET text = ? WHERE inner_key = ?&quot;;   sql.query(     queryUpdate,     [deal.text, inner_key],     (err, res) =&gt; {  \/\/\u043c\u043e\u0449\u043d\u0430\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043e\u0448\u0438\u0431\u043e\u043a       }       \/\/\u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445       \/\/\u0414\u0430\u043b\u044c\u0448\u0435 \u0438\u0434\u0435\u0442 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435    const queryDelete = &quot;DELETE FROM TODO WHERE inner_key = ?&quot;;   sql.query(queryDelete, inner_key, (err, res) =&gt; { \t\/\/ \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043e\u0448\u0438\u0431\u043e\u043a     } <\/code><\/pre>\n<p>  \u041a\u0430\u043a \u0432\u044b \u0437\u0430\u043c\u0435\u0442\u0438\u043b\u0438, \u0443 \u043c\u0435\u043d\u044f \u0437\u0434\u0435\u0441\u044c \u043d\u0435\u043f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u0434, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0434\u0430\u0436\u0435 \u0444\u0438\u0433\u0443\u0440\u043d\u044b\u0435 \u0441\u043a\u043e\u0431\u043a\u0438 \u043d\u0435 \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u044e\u0442\u0441\u044f, \u043d\u043e \u043f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u0434 \u044f \u043d\u0435 \u0432\u0438\u0436\u0443 \u0441\u043c\u044b\u0441\u043b \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442\u044c \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e. \u0415\u0441\u043b\u0438 \u0432\u0441\u0435-\u0442\u0430\u043a\u0438 \u0447\u0442\u043e-\u0442\u043e \u043d\u0435\u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0435\u0433\u043e <a href=\"https:\/\/github.com\/isakura313\/CRUD_API\"> \u0437\u0434\u0435\u0441\u044c <\/a>.<\/p>\n<h3> \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0441\u0432\u043e\u0435\u0433\u043e \u041a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430 <\/h3>\n<p>  \u0412 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0435 \u043c\u044b \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0430\u043c\u0438 \u0432 \u043c\u043e\u0434\u0435\u043b\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438. \u0415\u0441\u043b\u0438 \u0432 \u043e\u0431\u0449\u0435\u043c, \u0442\u043e \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u043c\u044b \u0432\u0430\u043b\u0438\u0434\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0437\u0430\u043f\u0440\u043e\u0441 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u044f \u043d\u0435 \u0431\u044b\u043b\u043e \u043b\u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043e \u043f\u0443\u0441\u0442\u043e\u0435 \u0442\u0435\u043b\u043e (\u0435\u0441\u043b\u0438 \u0432\u044b \u043f\u043b\u0430\u043d\u0438\u0440\u0443\u0435\u0442\u0435 \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0438\u0442\u044c API \u0432 \u043e\u0442\u043a\u0440\u044b\u0442\u043e\u0435, \u0442\u043e \u044d\u0442\u043e must have, \u0434\u0430 \u0438 \u0432\u043e\u043e\u0431\u0449\u0435 \u044d\u0442\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u043e). \u0414\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0438\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f, \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0442\u043e\u0433\u043e, \u043d\u0443\u0436\u043d\u043e \u043b\u0438 \u0447\u0442\u0435\u043d\u0438\u0435 <code>res.id<\/code> \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u0438\u043b\u0438 \u044d\u0442\u043e \u043d\u0435 \u0443\u0442\u043e\u0447\u043d\u0435\u043d\u043d\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441. \u0412 \u043c\u0435\u0442\u043e\u0434\u0435 <code>findAll<\/code> \u044f \u043e\u0441\u0442\u0430\u0432\u0438\u043b \u0440\u0430\u0437\u0440\u0435\u0448\u0430\u044e\u0449\u0438\u0435 \u0432\u0441\u0435 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438 \u043e\u0442\u0432\u0435\u0442\u0430 \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0441\u0432\u043e\u0435\u0433\u043e API.<\/p>\n<pre><code class=\"javascript\">     const Deal = require(&quot;..\/models\/deal.model.js&quot;);  \/\/\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u043d\u043e\u0432\u043e\u0435 \u0434\u0435\u043b\u043e exports.create = (req, res) =&gt; {   \/\/  \u0412\u0430\u043b\u0438\u0434\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0437\u0430\u043f\u0440\u043e\u0441   if (!req.body) {     res.status(400).send({       message: &quot;\u0423 \u043d\u0430\u0441 \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u043d\u0435 \u0431\u044b\u0442\u044c \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0430&quot;     });   }    \/\/ \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0441\u0432\u043e\u0435\u0433\u043e \u0434\u0435\u043b\u0430    const deal = new Deal({     text: req.body.text,     inner_key: req.body.inner_key     \/\/ \u0443 \u043d\u0430\u0448\u0435\u0433\u043e \u0434\u0435\u043b\u0430 \u0431\u0443\u0434\u0435\u0442 \u0442\u0435\u043a\u0441\u0442 \u0438 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0439 id, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043a\u0430\u043a      \/\/ \u043a\u043b\u044e\u0447 \u0434\u043b\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0432 React   });     Deal.create(deal, (err, data) =&gt; {     if (err)       res.status(500).send({         message:           err.message || &quot;\u041f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u0430 \u043e\u0448\u0438\u0431\u043a\u0430 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043a\u043e\u0434\u0430&quot;       });     else res.send(data);   }); };  \/\/ \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0432\u0441\u0435\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0438\u0437 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 exports.findAll = (req, res) =&gt; {   Deal.getAll((err, data) =&gt; {     if (err)       res.status(500).send({         message:           err.message || &quot;\u0427\u0442\u043e-\u0442\u043e \u0441\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0432\u0441\u0435\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439&quot;       });     else      res.setHeader('Access-Control-Allow-Origin', '*');     res.setHeader('Access-Control-Allow-Headers', 'origin, content-type, accept');     \/\/ \u044f \u043e\u0441\u0442\u0430\u0432\u043b\u044e \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438, \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c\u044b\u0435 \u0441 \u0441\u0435\u0440\u0432\u0435\u0440\u0430, \u0432 \u0442\u0430\u043a\u043e\u043c \u0432\u0438\u0434\u0435, \u043d\u043e \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u043c \u043f\u0440\u043e\u0434\u0430\u043a\u0448\u0435\u043d\u0435 \u043b\u0443\u0447\u0448\u0435 \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0442\u044c \u043f\u043e\u0434 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0439 origin     \/\/ \u043d\u0443 \u0438\u043b\u0438 \u0432\u044b \u0434\u0435\u043b\u0430\u0435\u0442\u0435 open API \u043a\u0430\u043a\u043e\u0439-\u043d\u0438\u0431\u0443\u0434\u044c, \u0442\u043e\u0433\u0434\u0430 \u0434\u0435\u043b\u0430\u0435\u0442\u0435 \u0447\u0442\u043e \u0445\u043e\u0442\u0438\u0442\u0435     res.send(data);   }); }; <\/code><\/pre>\n<p>  \u041e\u0441\u0442\u0430\u043b\u044c\u043d\u0443\u044e \u0447\u0430\u0441\u0442\u044c \u043a\u043e\u0434\u0430 \u044f \u0437\u0430\u043f\u0438\u0445\u043d\u0443 \u043f\u043e\u0434 <i>spoiler<\/i>, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u044b\u0448\u0435\u0443\u043f\u043e\u043c\u044f\u043d\u0443\u0442\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438. \u041e\u0434\u043d\u0430\u043a\u043e \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u043a\u043e\u0434\u0430 \u0442\u043e\u0436\u0435 \u0440\u0430\u0431\u043e\u0447\u0430\u044f, \u043d\u043e \u043e\u043d\u0430 \u0442\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u0438 \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430\u043c\u0438 \u043e\u0442 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0443\u0436\u0435 \u0431\u044b\u043b\u043e \u043e\u0437\u0432\u0443\u0447\u0435\u043d\u043e:<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u043e\u0441\u0442\u0430\u043b\u044c\u043d\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u043a\u043e\u0434\u0430<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"javascript\">\/\/  \u041d\u0430\u0439\u0442\u0438 \u043e\u0434\u043d\u043e \u0434\u0435\u043b\u043e \u043f\u043e \u043e\u0434\u043d\u043e\u043c\u0443 inner_id exports.findOne = (req, res) =&gt; {   Deal.findById(req.params.dealId, (err, data) =&gt; {     if (err) {       if (err.kind === &quot;not_found&quot;) {         res.status(404).send({           message: `\u041d\u0435\u0442 \u0434\u0435\u043b\u0430 \u0441 id ${req.params.dealId}.`         });       } else {         res.status(500).send({           message: &quot;\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0441 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043f\u043e id&quot; + req.params.dealId         });       }     } else res.send(data);   }); };  \/\/ \u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043f\u043e inner_id exports.update = (req, res) =&gt; {   \/\/ \u0432\u0430\u043b\u0438\u0434\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0437\u0430\u043f\u0440\u043e\u0441   if (!req.body) {     res.status(400).send({       message: &quot;\u041a\u043e\u043d\u0442\u0435\u043d\u0442 \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u0443\u0441\u0442\u043e\u0439&quot;     });   }  \/\/ \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0434\u0435\u043b\u0430 \u043f\u043e &quot;\u0430\u0439\u0434\u0438&quot; - \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 inner_key   Deal.updateById(     req.params.dealId,     new Deal(req.body),     (err, data) =&gt; {       if (err) {         if (err.kind === &quot;not_found&quot;) {           res.status(404).send({             message: `\u041d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d\u043e \u0434\u0435\u043b\u043e \u0441 id ${req.params.dealId}.`           });         } else {           res.status(500).send({             message: &quot;Error updating deal with id &quot; + req.params.dealId           });         }       } else res.send(data);     }   ); };  \/\/ \u0443\u0434\u0430\u043b\u0438\u0442\u044c \u0434\u0435\u043b\u043e \u043f\u043e inner_key exports.delete = (req, res) =&gt; {   Deal.remove(req.params.dealId, (err, data) =&gt; {     if (err) {       if (err.kind === &quot;not_found&quot;) {         res.status(404).send({           message: `\u041d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d\u043e \u0434\u0435\u043b\u043e \u0441 ${req.params.dealId}.`         });       } else {         res.status(500).send({           message: &quot;\u041d\u0435 \u043c\u043e\u0433\u0443 \u0443\u0434\u0430\u043b\u0438\u0442\u044c \u0434\u0435\u043b\u043e \u0441 &quot; + req.params.dealId         });       }     } else res.send({ message: `\u0434\u0435\u043b\u043e \u0431\u044b\u043b\u043e \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u0443\u0434\u0430\u043b\u0435\u043d\u043e` });   }); };  \/\/ \u0423\u0434\u0430\u043b\u0438\u0442\u044c \u0432\u0441\u0435 \u0434\u0435\u043b\u0430 \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u044b exports.deleteAll = (req, res) =&gt; {   Deal.removeAll((err, data) =&gt; {     if (err)       res.status(500).send({         message:           err.message || &quot;\u0427\u0442\u043e-\u0442\u043e \u043f\u043e\u0448\u043b\u043e \u043d\u0435 \u0442\u0430\u043a \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u0432\u0441\u0435\u0445 \u0434\u0435\u043b&quot;       });     else res.send({ message: `\u0412\u0441\u0435 \u0434\u0435\u043b\u0430 \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u0443\u0434\u0430\u043b\u0435\u043d\u044b` });   }); };    <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<h3> \u0420\u043e\u0443\u0442\u0438\u043d\u0433 <\/h3>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043a \u0441\u0430\u043c\u043e\u043c\u0443 \u0441\u043b\u0430\u0434\u043a\u043e\u043c\u0443 \u0438 \u043f\u0440\u043e\u0441\u0442\u043e\u043c\u0443: \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0440\u043e\u0443\u0442\u0438\u043d\u0433\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0442\u043e\u043c \u043d\u0430\u0434\u043e \u043d\u0435 \u0437\u0430\u0431\u044b\u0442\u044c \u043f\u0440\u043e\u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0442\u043e\u043c \u0432 \u0441\u0430\u043c server.js. \u041f\u043e \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u043c \u043f\u0443\u0442\u044f\u043c \u0438 \u043c\u0435\u0442\u043e\u0434\u0430\u043c \u043c\u044b \u0441\u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435. \u0412 \u043d\u0430\u0448\u0435\u0439 \u043f\u0430\u043f\u043a\u0435 app \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043f\u043e\u0434\u043f\u0430\u043f\u043a\u0443 routes, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0444\u0430\u0439\u043b <code>deals.routes.js<\/code>. \u0412 \u043d\u0435\u043c \u043d\u0443\u0436\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<pre><code class=\"javascript\">module.exports = app =&gt; {  \/\/\u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u043d\u0430\u0448 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440, \u0447\u0442\u043e \u0431\u044b \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0438\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0443      const deals = require(&quot;..\/controllers\/deal.controller.js&quot;);        \/\/ \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043d\u043e\u0432\u043e\u0433\u043e \u0434\u0435\u043b\u0430 \u043f\u043e \u043c\u0435\u0442\u043e\u0434\u0443 post     app.post(&quot;\/deals&quot;, deals.create);        \/\/ \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0432\u0441\u0435\u0445 \u0434\u0435\u043b \u0441\u0440\u0430\u0437\u0443     app.get(&quot;\/deals&quot;, deals.findAll);        \/\/\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0434\u0435\u043b\u0430 \u043f\u043e id (\u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u0432 \u0437\u0430\u043f\u0440\u043e\u0441\u0435 \u0434\u043e\u043b\u0436\u0435\u043d inner_key), \u043d\u043e \u044f \u043d\u0435 \u0441\u0442\u0430\u043b \u044d\u0442\u043e \u043c\u0435\u043d\u044f\u0442\u044c     app.get(&quot;\/deal\/:dealId&quot;, deals.findOne);        \/\/ \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c \u0434\u0435\u043b\u043e \u043f\u043e id     \/\/ \u0437\u0434\u0435\u0441\u044c \u0442\u043e\u0436\u0435 \u0441\u0430\u043c\u043e\u0435 \u043f\u0440\u043e inner_key     app.put(&quot;\/deal\/:dealId&quot;, deals.update);        \/\/\u0423\u0434\u0430\u043b\u0438\u0442\u044c \u0434\u0435\u043b\u043e \u043f\u043e id     app.delete(&quot;\/deal\/:dealId&quot;, deals.delete);        \/\/ \u0423\u0434\u0430\u043b\u0438\u0442\u044c \u0441\u0440\u0430\u0437\u0443 \u0432\u0441\u0435 \u0434\u0435\u043b\u0430     app.delete(&quot;\/deals&quot;, deals.deleteAll);   };   <\/code><\/pre>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u043d\u0430\u0448 \u0444\u0430\u0439\u043b <code>server.js<\/code> \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043d\u0430\u0434 \u043f\u0440\u043e\u0441\u043b\u0443\u0448\u043a\u043e\u0439 \u043f\u043e\u0440\u0442\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<pre><code class=\"javascript\">  require(&quot;.\/app\/routes\/deals.routes.js&quot;)(app);   <\/code><\/pre>\n<h4>\u041d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u0430\u0448\u0435\u0433\u043e API <\/h4>\n<p>  \u0412 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0435 \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0445 \u0441\u0442\u0430\u0442\u0435\u0439 \u0432 \u043a\u043e\u043d\u0446\u0435 \u0442\u0435\u0441\u0442\u0438\u0440\u0443\u044e\u0442 API \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <a href=\"https:\/\/www.postman.com\/\">POSTMAN<\/a>. \u042d\u0442\u043e \u0438 \u0432\u043f\u0440\u0430\u0432\u0434\u0443 \u043e\u0442\u043b\u0438\u0447\u043d\u044b\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u0430\u043c \u0441\u0442\u043e\u0438\u0442 \u043e\u0441\u0432\u043e\u0438\u0442\u044c, \u0435\u0441\u043b\u0438 \u043f\u043b\u0430\u043d\u0438\u0440\u0443\u0435\u0442\u0435 \u0445\u043e\u0442\u044c \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0437\u0430\u043d\u0438\u043c\u0430\u0442\u044c\u0441\u044f \u043f\u0440\u043e\u0444\u0435\u0441\u0441\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u043e\u0439 API (\u0438 \u043d\u0435 \u0441\u0442\u043e\u043b\u044c \u0432\u0430\u0436\u043d\u043e, \u0434\u043b\u044f \u043a\u0430\u043a\u043e\u0439 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u044b \u0438 \u043d\u0430 \u043a\u0430\u043a\u043e\u043c \u044f\u0437\u044b\u043a\u0435). \u0415\u0441\u043b\u0438 \u0432\u044b \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0432\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0438 \u043d\u0430 \u0437\u0430\u0431\u044b\u043b\u0438 \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0432\u0430\u0448\u0443 \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445, \u0442\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u0438 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0441\u0430\u043c\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435:<\/p>\n<pre><code class=\"plaintext\">&lt;node server.js&gt; <\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u0432\u044b \u0441\u043e\u0432\u0441\u0435\u043c \u043d\u043e\u0432\u0438\u0447\u043e\u043a, \u0442\u043e \u0432\u0430\u043c \u0431\u0443\u0434\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u0443\u0441\u043b\u044b\u0448\u0430\u0442\u044c \u043e \u043f\u0430\u043a\u0435\u0442\u0435 <code>nodemon<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u0432\u0430\u0448\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u0435\u0441\u043b\u0438 \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432 \u0444\u0430\u0439\u043b\u0430\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u0430:<\/p>\n<pre><code class=\"plaintext\">  npm i nodemon -g   nodemon server.js <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0431\u0443\u0434\u0435\u0442 \u043a\u0443\u0434\u0430 \u043f\u0440\u043e\u0449\u0435 \u043e\u0442\u043b\u0430\u0436\u0438\u0432\u0430\u0442\u044c \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u044e\u0449\u0438\u0435 \u043e\u0448\u0438\u0431\u043a\u0438. \u041d\u043e \u043c\u044b \u0441\u043e\u0431\u0438\u0440\u0430\u043b\u0438\u0441\u044c \u043f\u0440\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u043c React-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438.<\/p>\n<p>  \u0423 \u043c\u0435\u043d\u044f \u0435\u0441\u0442\u044c \u043f\u043e\u0434 \u0440\u0443\u043a\u043e\u0439 \u043f\u0440\u043e\u0441\u0442\u043e\u0435 react- todo, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u044c \u043c\u043e\u0433 \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c \u0432 \u0441\u0442\u0430\u0442\u044c\u0435  \u0434\u0435\u043f\u043b\u043e\u044f react \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0430 Heroku \u044d\u0442\u043e\u0433\u043e \u0431\u043b\u043e\u0433\u0430. \u041e\u0434\u043d\u0430\u043a\u043e \u044f \u043d\u0435 \u0431\u0443\u0434\u0443\u0442 \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0432\u0435\u0441\u044c \u0431\u044d\u043a \u043f\u043e\u0434 \u043d\u0430\u0448\u0435 react \u2014 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 (\u0445\u043e\u0442\u044f \u044d\u0442\u043e \u0441\u043e\u0432\u0441\u0435\u043c \u043d\u0435 \u0441\u043b\u043e\u0436\u043d\u043e, \u043d\u043e \u044f \u043d\u0435 \u0445\u043e\u0447\u0443 \u0447\u0440\u0435\u0437\u043c\u0435\u0440\u043d\u043e \u0443\u0434\u043b\u0438\u043d\u044f\u0442\u044c \u0441\u0442\u0430\u0442\u044c\u044e). \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u044f \u0437\u0430\u043f\u0443\u0449\u0443 React \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043d\u0430 \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u043e\u043c \u0441\u0435\u0440\u0432\u0435\u0440\u0435 <code>create-react-app<\/code> \u043f\u043e\u0434 3000 \u043f\u043e\u0440\u0442\u043e\u043c, \u0430 \u043d\u0430\u0448\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043f\u043e\u0434 5003 \u043f\u043e\u0440\u0442\u043e\u043c. \u041f\u0443\u0441\u043a\u0430\u0439 \u0442\u0435\u043f\u0435\u0440\u044c \u043d\u0430 \u043d\u0430\u0448\u0435\u043c \u043f\u0443\u0442\u0438 \u0438 \u0441\u0442\u043e\u044f\u0442 \u0442\u0440\u0443\u0434\u043d\u043e\u043f\u0440\u043e\u0445\u043e\u0434\u0438\u043c\u044b\u0435 CORS, \u043c\u044b \u043b\u0435\u0433\u043a\u043e \u0441\u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043d\u0430\u0448\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u0445\u043e\u0442\u044f \u0431\u044b \u0432\u0441\u0435 todo. \u041f\u0440\u0438\u043c\u0435\u0440 \u0440\u0430\u0431\u043e\u0442\u044b \u043d\u0430\u0448\u0438\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u044f \u043f\u043e\u0447\u0442\u0438 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0432\u0437\u044f\u043b \u0441 \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0439 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 React, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u0441\u0432\u044f\u0449\u0435\u043d\u0430 fetch \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u043c. \u0417\u0430\u043f\u0440\u043e\u0441\u044b \u0432 React \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u0445 \u043e\u0431\u044b\u0447\u043d\u043e \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043f\u043e\u0441\u043b\u0435 \u0440\u0435\u043d\u0434\u0435\u0440\u0438\u043d\u0433\u0430 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u0432 componentDidMount, \u0438 \u0438\u043c\u0435\u043d\u043d\u043e \u0432 \u043d\u0435\u043c \u043d\u0443\u0436\u043d\u043e \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043a \u0443\u0434\u0430\u043b\u0435\u043d\u043d\u044b\u043c \u0440\u0435\u0441\u0443\u0440\u0441\u0430\u043c:<\/p>\n<pre><code class=\"javascript\">   class App extends Component{     constructor(){       super()       this.state ={         error: null,         isLoaded: false,         items:[],         currentItem: {text:&quot;\u043f\u0435\u0440\u0432\u043e\u0435 \u0434\u0435\u043b\u043e&quot;, inner_key:&quot;firstItem&quot;}                }     }     componentDidMount() {       fetch(&quot;http:\/\/localhost:5003\/deals&quot;)         .then(res =&gt; res.json())         .then(           (result) =&gt; {             this.setState({               \/\/\u0435\u0441\u043b\u0438 \u0438 \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u0430 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0430, \u0442\u043e\u0433\u0434\u0430 \u043c\u044b \u0430\u043a\u0442\u0438\u0432\u0438\u0440\u0443\u0435\u043c \u043d\u0430\u0448 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442               isLoaded: true,               items: result             });           },           \/\/ \u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435: \u0432\u0430\u0436\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438 \u0438\u043c\u0435\u043d\u043d\u043e \u0437\u0434\u0435\u0441\u044c, \u0430 \u043d\u0435 \u0432 \u0431\u043b\u043e\u043a\u0435 catch(),           \/\/ \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0438\u0437 \u043e\u0448\u0438\u0431\u043e\u043a \u0432 \u0441\u0430\u043c\u0438\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430\u0445.           (error) =&gt; {             this.setState({               isLoaded: true,               error             });           }         )     } <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0434\u0435\u043b\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0434\u0442\u044f\u0433\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u0438\u0437 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445:<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/dh\/_f\/uw\/dh_fuwjeag3lohk39_lztugufou.png\"><\/p>\n<p>  \u0412\u0441\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0438 \u0432 \u0441\u0430\u043c\u043e\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438:<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/tc\/r_\/eh\/tcr_ehblld5-tmt3liepqslbf1a.png\"><\/p>\n<p>  \u041d\u0430 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0432\u0441\u0435\u0445 \u0434\u0435\u043b \u043d\u0430\u0448\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442. \u041e\u0434\u043d\u0430\u043a\u043e \u0432 React \u2014 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u043f\u043e\u043a\u0430 \u043d\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u044b \u043c\u0435\u0442\u043e\u0434\u044b \u043d\u0438 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f, \u043d\u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u0435\u043b. \u0427\u0442\u043e\u0431\u044b \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c cors \u2014 \u0437\u0430\u043f\u0440\u043e\u0441\u044b, \u0432\u0430\u043c \u0441\u0442\u043e\u0438\u0442 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432 node-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u043e\u0431\u0441\u043b\u0443\u0436\u0438\u0432\u0430\u043d\u0438\u0435 js-\u0431\u0438\u043b\u0434\u0430 \u043d\u0430 React, \u0438 \u0442\u043e\u0433\u0434\u0430 \u0440\u0430\u0441\u043f\u0438\u0441\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434\u044b \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u0435\u043b \u043f\u043e <code>inner_id<\/code>, \u0438\u0445 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f. <\/p>\n<p>  \u0412\u0441\u0435\u043c \u0441\u043f\u0430\u0441\u0438\u0431\u043e \u0437\u0430 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435. \u041f\u043e \u0442\u0440\u0430\u0434\u0438\u0446\u0438\u0438, \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0445 \u0441\u0441\u044b\u043b\u043e\u043a:<\/p>\n<p>  <a href=\"https:\/\/expressjs.com\/ru\/guide\/migrating-4.html\"> \u041d\u0435\u043c\u043d\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0433\u043e \u0438\u0437 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 express \u043f\u043e \u043f\u043e\u0432\u043e\u0434\u0443 \u0440\u0430\u0431\u043e\u0442\u044b middleware, \u0432 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438 body-express <\/a><br \/>  <a href=\"https:\/\/ua-blog.com\/%D0%B8%D1%81%D0%BF%D0%BE%D0%BB%D1%8C%D0%B7%D0%BE%D0%B2%D0%B0%D0%BD%D0%B8%D0%B5-axios-%D0%B2-react\/\"> \u041f\u0438\u0441\u0430\u0442\u044c \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043d\u0430 React \u0431\u0435\u0437 axios \u0443\u0436\u0435 \u0441\u043e\u0432\u0441\u0435\u043c \u043d\u0435 \u043c\u043e\u0434\u043d\u043e<\/a><br \/>  <a href=\"https:\/\/expressjs.com\/en\/resources\/middleware\/cors.html\"> \u0418 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u0440\u043e \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u043d\u0438\u0435 cors \u0432 Express, \u0440\u0430\u0437 \u043e \u043d\u0435\u043c \u0437\u0430\u0448\u043b\u0430 \u0440\u0435\u0447\u044c<\/a><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/company\/otus\/blog\/491786\/\"> https:\/\/habr.com\/ru\/company\/otus\/blog\/491786\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/company\/otus\/blog\/491786\/\"><i><b>\u0412\u0441\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442. \u0412 \u043f\u0440\u0435\u0434\u0434\u0432\u0435\u0440\u0438\u0438 \u0441\u0442\u0430\u0440\u0442\u0430 \u043a\u0443\u0440\u0441\u0430 <a href=\"https:\/\/otus.pw\/3iFx\/\">\u00ab\u0420\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a Node.js\u00bb<\/a>, \u0445\u043e\u0442\u0438\u043c \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435\u043c <a href=\"https:\/\/habr.com\/ru\/company\/otus\/blog\/491408\/\">\u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0430<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u044b\u043b \u043d\u0430\u043f\u0438\u0441\u0430\u043d \u043d\u0430\u0448\u0438\u043c \u0432\u043d\u0435\u0448\u0442\u0430\u0442\u043d\u044b\u043c \u0430\u0432\u0442\u043e\u0440\u043e\u043c.<\/b><\/i><\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/ly\/hi\/h2\/lyhih2n_wa-5o-ot-lsa-ly7wgy.png\">  <\/p>\n<hr>\n<p>  \u0412\u0441\u0435\u043c \u0435\u0449\u0435 \u0440\u0430\u0437 \u043f\u0440\u0438\u0432\u0435\u0442. \u041c\u044b \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u0441\u044f \u043a \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0430 Node.js \u0438 MySQL \u0434\u043b\u044f \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e todo \u2014 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0430 Node.js \u0434\u043b\u044f React. \u0421 \u043f\u0440\u043e\u0448\u043b\u043e\u0433\u043e \u0440\u0430\u0437\u0430 \u044f \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u0435\u0440\u0435\u0441\u043c\u043e\u0442\u0440\u0435\u043b \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0438 \u0442\u0435\u043f\u0435\u0440\u044c \u0440\u0435\u0448\u0438\u043b \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u043a\u043e\u043b\u043e\u043d\u043a\u0443 \u0432 \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e\u0434 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c <code>inner_key<\/code>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u0430 \u043d\u0430\u043c \u0434\u043b\u044f \u043e\u0442\u0440\u0438\u0441\u043e\u0432\u043a\u0438 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0445 \u043a\u043b\u044e\u0447\u0435\u0439 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0434\u0435\u043b\u0430 (\u0432 \u0441\u043f\u0438\u0441\u043a\u0435 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u044e\u0449\u0438\u0445\u0441\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 React \u043d\u0443\u0436\u0435\u043d \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u043a\u043b\u044e\u0447 \u043d\u0430 \u043a\u0430\u0436\u0434\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0434\u043b\u044f \u0435\u0433\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0432 Virtual DOM. \u0415\u0441\u043b\u0438 \u044d\u0442\u043e \u043f\u043e \u043f\u0440\u0435\u0436\u043d\u0435\u043c\u0443 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u0443 \u0432\u0430\u0441 \u0432\u043e\u043f\u0440\u043e\u0441\u044b, \u0432\u0430\u043c \u0441\u0442\u043e\u0438\u0442 \u0438\u0437\u0443\u0447\u0438\u0442\u044c <a href=\"https:\/\/ru.reactjs.org\/docs\/lists-and-keys.html\">\u044d\u0442\u0443 \u0441\u0442\u0430\u0442\u044c\u044e<\/a>).<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-299915","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/299915","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=299915"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/299915\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=299915"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=299915"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=299915"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}