{"id":299772,"date":"2020-03-06T15:00:15","date_gmt":"2020-03-06T15:00:15","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=299772"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=299772","title":{"rendered":"\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0441\u0432\u043e\u044e CRUD API \u043d\u0430 Express \u0438 MySQL: \u0447\u0430\u0441\u0442\u044c \u043f\u0435\u0440\u0432\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\/491408\/\"><b><i>\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\/NZUM\/\">\u00abFullstack \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a JavaScript<\/a>\u00bb, \u0445\u043e\u0442\u0438\u043c \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u043c \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u043e\u043c, \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.<\/i><\/b><\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/9w\/az\/vb\/9wazvb3h8u0o1gjvijjntbhrkgk.png\"><\/p>\n<p>  Express \u043e\u0434\u0438\u043d \u0438\u0437 \u0441\u0430\u043c\u044b\u0445 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u0432\u0435\u0431-\u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0440\u043e\u0443\u0442\u0438\u043d\u0433, \u043c\u0438\u0434\u0434\u043b\u0432\u0435\u0439\u0440\u0441 \u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u0432. \u0414\u0435\u043b\u0430\u0442\u044c \u0431\u044d\u043a\u0435\u043d\u0434 \u043d\u0430 Node.js \u0431\u0435\u0437 Express \u0432 2020 \u0433\u043e\u0434\u0443 \u2014 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0441\u0442\u0440\u0430\u043d\u043d\u043e\u0435 \u0437\u0430\u043d\u044f\u0442\u0438\u0435, \u0432\u0435\u0434\u044c Express \u0434\u0435-\u0444\u0430\u043a\u0442\u043e \u2014 \u043a\u0430\u0440\u043a\u0430\u0441 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0432\u0435\u0431-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0430 Node.js. <br \/>  \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u043c\u044b \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043d\u0435\u0441\u043b\u043e\u0436\u043d\u043e\u0435 CRUD API \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 MySQL. \u041e\u043f\u044b\u0442\u043d\u044b\u0439 \u0432 Node.js \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u044c \u0441\u043f\u0440\u043e\u0441\u0438\u0442, \u0430 \u0433\u0434\u0435 \u0436\u0435 MongoDB, \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c Node.js \u043e\u0431\u044b\u0447\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u0441\u044f \u0432 \u043f\u0430\u0440\u0435 \u043d\u043e, \u0441\u043a\u0430\u0436\u0443 \u0441\u0440\u0430\u0437\u0443, \u044d\u0442\u043e \u0441\u0442\u0430\u0442\u044c\u044f \u0431\u043e\u043b\u044c\u0448\u0435 \u0434\u043b\u044f PHP \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0445\u043e\u0442\u044f\u0442 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u043e\u0442\u0440\u043e\u0433\u0430\u0442\u044c Node.js, \u0438 \u0447\u0442\u043e\u0431\u044b \u0441\u043c\u044f\u0433\u0447\u0438\u0442\u044c \u043f\u0435\u0440\u0435\u0445\u043e\u0434 \u0432 \u043d\u043e\u0432\u0443\u044e \u044d\u043a\u043e\u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u043c\u044b \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f MySQL. API \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u043d\u0435\u0441\u043b\u043e\u0436\u043d\u043e\u0433\u043e Todo \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u043d\u0430 \u0442\u043e\u0442 \u0441\u043b\u0443\u0447\u0430\u0439, \u0435\u0441\u043b\u0438 \u043a\u0442\u043e-\u0442\u043e \u0437\u0430\u0445\u043e\u0447\u0435\u0442 \u043a \u0441\u0432\u043e\u0435\u0439 todo (\u0438 \u0434\u0430\u0436\u0435 \u043d\u0435\u0432\u0430\u0436\u043d\u043e, \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u0439 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e React \u0438\u043b\u0438 \u043d\u0435\u0442), \u043f\u0440\u0438\u0441\u043e\u0435\u0434\u0438\u043d\u0438\u0442\u044c \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0431\u044d\u043a\u0430 \u0438 \u043f\u043e\u0438\u0433\u0440\u0430\u0442\u044c \u0441 \u043d\u0438\u043c.<\/p>\n<p>  <a name=\"habracut\"><\/a><\/p>\n<h5> \u00ab\u0410\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430\u00bb \u0438 \u0441\u0443\u0442\u044c \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f<\/h5>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/jh\/jh\/si\/jhjhsi1hno_tuosqmjuft3algig.jpeg\"><\/p>\n<p>  \u0412 \u043d\u0430\u0448\u0435\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u043c\u043e\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c, \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c, \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0442\u044c \u0438 \u0443\u0434\u0430\u043b\u044f\u0442\u044c Todo. \u0412 \u043e\u0431\u0449\u0435\u043c, \u0443 \u043d\u0430\u0441 \u0431\u0443\u0434\u0435\u0442 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u043d\u0430\u0431\u043e\u0440 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 CRUD (create read update delete).<\/p>\n<p>  \u0412 \u043a\u043e\u043d\u0446\u0435 \u043c\u044b \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435\u043c \u043d\u0430 React \u0438 \u0432\u0441\u0435 \u043f\u0440\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c.<\/p>\n<p>  \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u0440\u0438\u0432\u0435\u0434\u0443 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0444\u0430\u0439\u043b\u043e\u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f:<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/i_\/ad\/nq\/i_adnqzj03nofwn7xqkgjki-ono.png\"><\/p>\n<p>  \u0414\u0430\u043b\u044c\u0448\u0435 \u044f \u043f\u0440\u0438\u0432\u0435\u0434\u0443 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 \u0438 \u043c\u0435\u0442\u043e\u0434\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0435\u0441\u0442\u044c \u0432 \u043d\u0430\u0448\u0435\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438:<\/p>\n<div class=\"scrollable-table\">\n<table>\n<thead>\n<tr>\n<th>\u041c\u0435\u0442\u043e\u0434\u044b<\/th>\n<th>Url<\/th>\n<th>\u0414\u0435\u0439\u0441\u0442\u0432\u0438\u044f<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<th> GET<\/th>\n<th>\/deals<\/th>\n<th>\u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0432\u0441\u0435\u0445 \u0434\u0435\u043b<\/th>\n<\/tr>\n<tr>\n<th>GET<\/th>\n<th>\/deals\/2<\/th>\n<th>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 id c \u043d\u043e\u043c\u0435\u0440\u043e\u043c 2<\/th>\n<\/tr>\n<tr>\n<th>POST<\/th>\n<th>\/deals <\/th>\n<th> \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043d\u043e\u0432\u043e\u0433\u043e \u0434\u0435\u043b\u0430<\/th>\n<\/tr>\n<tr>\n<th>PUT <\/th>\n<th>\/deals\/3 <\/th>\n<th> \u041e\u0431\u043d\u043e\u0432\u0438\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0441 id=3<\/th>\n<\/tr>\n<tr>\n<th>DELETE <\/th>\n<th>\/deals\/3 <\/th>\n<th> \u0443\u0434\u0430\u043b\u0438\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0441 id=3<\/th>\n<\/tr>\n<tr>\n<th>DELETE <\/th>\n<th>\/deals <\/th>\n<th> \u0443\u0434\u0430\u043b\u0438\u0442\u044c \u0432\u0441\u0435\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439<\/th>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<h5> \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0441\u0432\u043e\u0435\u0433\u043e Node.js \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f <\/h5>\n<p>  \u041f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u0432 \u0432\u0430\u0448\u0443 \u043b\u044e\u0431\u0438\u043c\u0443\u044e \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044e, \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b \u0438 \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0432\u0430\u0448\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435. \u041a\u0441\u0442\u0430\u0442\u0438, \u0438\u0437 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430, \u043d\u0430\u0432\u0435\u0440\u043d\u043e\u0435, \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u0447\u0442\u043e Node.js \u0443 \u0432\u0430\u0441 \u0443\u0436\u0435 \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0430. \u0415\u0441\u043b\u0438 \u0432\u044b \u0435\u0449\u0435 \u044d\u0442\u043e\u0433\u043e \u043d\u0435 \u0441\u0434\u0435\u043b\u0430\u043b\u0438, \u0442\u043e <strike>\u044d\u0442\u043e\u0433\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c<\/strike> \u0441\u043a\u0430\u0447\u0430\u0439\u0442\u0435 \u043f\u043e <a href=\"https:\/\/nodejs.org\/en\/\"> \u0441\u0441\u044b\u043b\u043a\u0435 <\/a> \u043e\u0442\u0441\u044e\u0434\u0430. <\/p>\n<pre><code class=\"plaintext\">    $ mkdir CRUD_API     $ cd CRUD_API <\/code><\/pre>\n<p>  \u0414\u0430\u043b\u044c\u0448\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0448\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <i>npm init<\/i>. \u0422.\u043a. \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0443 \u043d\u0430\u0441 \u0441\u043a\u043e\u0440\u0435\u0435 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0435 \u0438 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0435\u0435, \u044f \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0441\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u043d\u043e\u0439, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u0442 \u0432\u0441\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e \u0434\u0435\u0444\u043e\u043b\u0442\u0443, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u0442\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u0440\u0435\u043c\u044f \u043d\u0430 \u043c\u0435\u043b\u043a\u0438\u0435 \u0434\u0435\u0442\u0430\u043b\u0438:<\/p>\n<pre><code class=\"plaintext\"> npm init -y  <\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u0447\u0442\u043e, \u043f\u043e\u0442\u043e\u043c \u0440\u0443\u043a\u0430\u043c\u0438 \u0432 <code>package.json<\/code> \u0432\u044b \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u043c\u0435\u043d\u044f\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0430 \u0442\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u044b: \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439 github, \u0442\u044d\u0433\u0438, \u0430\u0432\u0442\u043e\u0440\u0430, \u0438 \u0442.\u0434. <br \/>  \u041f\u043e\u0442\u043e\u043c \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0432\u0441\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043f\u0430\u043a\u0435\u0442\u044b:<\/p>\n<pre><code class=\"plaintext\">  npm i express mysql body-parser --save <\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u0432\u044b \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u0442\u0435\u0441\u044c \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u043f\u043e\u0442\u043e\u043c \u0432\u0430\u0448\u0443 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u043d\u0430 github, \u0432\u0430\u043c \u0441\u0442\u043e\u0438\u0442 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u043a\u0440\u044b\u0442\u044b\u0439 \u0444\u0430\u0439\u043b <code>.gitignore<\/code>, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u0442\u0430\u0441\u043a\u0430\u0442\u044c \u0441 \u0441\u043e\u0431\u043e\u0439 \u0442\u044f\u0436\u0435\u043b\u0435\u0439\u0448\u0438\u0435 node_modules <strike>\u0438 \u043d\u0435 \u043f\u043e\u0437\u043e\u0440\u0438\u0442\u044c\u0441\u044f<\/strike>. \u041f\u0438\u0448\u0435\u043c:<\/p>\n<pre><code class=\"plaintext\">    touch .gitignore      code .gitignore  <\/code><\/pre>\n<p>  \u0422\u0430\u043c \u0432\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c <code>node_modules<\/code>, \u0432 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u043c \u0432 \u044d\u0442\u043e\u0442 \u0444\u0430\u0439\u043b \u0432\u044b \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u0432\u043f\u0438\u0441\u0430\u0442\u044c \u043d\u0430\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0430\u043f\u043e\u043a \u0438 \u0444\u0430\u0439\u043b\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0445\u043e\u0442\u0438\u0442\u0435 \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u043f\u043e\u0442\u043e\u043c \u043d\u0430 \u0443\u0434\u0430\u043b\u0435\u043d\u043d\u043e\u043c \u0441\u0435\u0440\u0432\u0435\u0440\u0435.<\/p>\n<h3> \u0411\u0430\u0437\u043e\u0432\u0430\u044f \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 Express<\/h3>\n<p>  \u0412 \u043a\u043e\u0440\u043d\u0435\u0432\u043e\u0439 \u043f\u0430\u043f\u043a\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0444\u0430\u0439\u043b <code>server.js<\/code>: <\/p>\n<pre><code class=\"javascript\">    const express = require(&quot;express&quot;);     const bodyParser = require(&quot;body-parser&quot;);          const app = express();          \/\/\u0434\u0435\u043b\u0430\u0435\u043c \u043d\u0430\u0448 \u043f\u0430\u0440\u0441\u0438\u043d\u0433 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 json     app.use(bodyParser.json());          \/\/ \u043f\u0430\u0440\u0441\u0438\u0442 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043f\u043e \u0442\u0438\u043f\u0443: application\/x-www-form-urlencoded     app.use(bodyParser.urlencoded({ extended: true }));          \/\/  \u043f\u0440\u043e\u0441\u0442\u043e\u0439 response - request     app.get(&quot;\/&quot;, (req, res) =&gt; {       res.json({ message: &quot;\u042d\u0442\u043e \u0441\u0442\u0430\u0440\u0442\u043e\u0432\u0430\u044f \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0430 \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f&quot; });     });          \/\/ \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u043f\u043e\u0440\u0442, \u0438 \u0441\u043b\u0443\u0448\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u044b     app.listen(3001, () =&gt; {       console.log(&quot;\u0421\u0435\u0440\u0432\u0435\u0440 \u0437\u0430\u043f\u0443\u0449\u0435\u043d \u043d\u0430 3001 \u043f\u043e\u0440\u0442\u0443&quot;);     }); <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0441\u0435\u0440\u0432\u0435\u0440 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e:<\/p>\n<pre><code class=\"plaintext\">node server.js <\/code><\/pre>\n<p>  Express \u043d\u0430\u043c \u043d\u0443\u0436\u0435\u043d \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u0432\u043e\u0435\u0433\u043e api, \u0430 \u043f\u0430\u043a\u0435\u0442 <i>body-parser<\/i> \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u043d\u0430\u043c \u043f\u0430\u0440\u0441\u0438\u0442\u044c <i>request<\/i> \u0438 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c <code>req.body<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u0442\u0441\u044f \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0440\u043e\u0443\u0442\u0438\u043d\u0433\u0430.<\/p>\n<p>  \u0421\u0435\u0439\u0447\u0430\u0441 \u043d\u0430\u0448 \u0441\u0435\u0440\u0432\u0435\u0440 \u0443\u043c\u0435\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<ul>\n<li> \u0421\u043e\u0437\u0434\u0430\u0435\u043c Express app, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0442\u0434\u0430\u0435\u0442 body-parser \u043c\u0438\u0434\u0434\u043b\u0435\u0432\u0435\u0438\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f app.use()<\/li>\n<li> \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u043e\u0439 get, \u043f\u0440\u043e\u0441\u0442\u043e \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f<\/li>\n<li> \u0421\u043b\u0443\u0448\u0430\u0435\u043c 3001 \u043f\u043e\u0440\u0442 \u043d\u0430 \u0432\u0441\u0435 \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f<\/li>\n<\/ul>\n<p>  \u041f\u0435\u0440\u0432\u0438\u0447\u043d\u043e \u043d\u0430\u0448\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u0434\u0430\u043b\u044c\u0448\u0435 \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043d\u044f\u0442\u044c\u0441\u044f \u0431\u0430\u0437\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<h5>\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0441\u0432\u043e\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 MySQL<\/h5>\n<p>  \u042f \u043e\u0447\u0435\u043d\u044c \u043d\u0430\u0434\u0435\u044e\u0441\u044c, \u0447\u0442\u043e \u0443 \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u044f \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u043d\u0435\u0442 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0441 \u0442\u0435\u043c, \u0447\u0442\u043e\u0431\u044b \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u043a\u0430\u0447\u0430\u0442\u044c \u0438 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c MySQL \u0438 MySQLWorkBranch. \u0414\u0430\u043b\u044c\u0448\u0435 \u0432\u044b \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0435 scheme(\u0411\u0414) \u0441 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u0430\u043c \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0440\u0430\u0432\u0438\u0442\u0441\u044f (\u0432 \u043c\u043e\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 TODO), \u0438 \u043f\u043e\u0442\u043e\u043c \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u043c\u043e\u043b\u043d\u0438\u044e-\u0437\u0430\u043f\u0440\u043e\u0441 \u0438 \u0441\u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u0442\u044c\/\u043d\u0430\u0431\u0440\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u043a\u043e\u043c\u0430\u043d\u0434\u0443:<\/p>\n<pre><code class=\"sql\">    CREATE TABLE IF NOT EXISTS `todo` (         id int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,         text varchar(255) NOT NULL       ) ENGINE=InnoDB DEFAULT CHARSET=utf8; <\/code><\/pre>\n<p>  \u0412 \u043d\u0430\u0448\u0435\u0439 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0431\u0443\u0434\u0435\u0442 \u0432\u0441\u0435 \u043f\u043e \u043c\u0438\u043d\u0438\u043c\u0443\u043c\u0443: \u0442\u043e\u043b\u044c\u043a\u043e id \u0438 \u0441\u0430\u043c \u0442\u0435\u043a\u0441\u0442 \u0434\u0435\u043b. \u041e\u0434\u043d\u0430\u043a\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0435\u0449\u0451 \u043a\u043e\u043b\u043e\u043d\u043e\u0447\u043a\u0443, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043c\u043e\u0436\u0435\u0442 \u043e\u043f\u0438\u0441\u0430\u043d\u0430, \u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0443, \u0441\u0440\u043e\u0447\u043d\u043e\u0441\u0442\u044c \u0432\u0430\u0448\u0435\u0433\u043e \u0434\u0435\u043b\u0430, \u043d\u0430\u0434\u0435\u044e\u0441\u044c, \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u043d\u0435 \u0432\u044b\u0437\u043e\u0432\u0435\u0442.<\/p>\n<h5> \u041a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f &amp; \u043a\u043e\u043d\u043d\u0435\u043a\u0442 \u0441 \u043d\u0430\u0448\u0435\u0439 \u0431\u0430\u0437\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445<\/h5>\n<p>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c \u0438 \u0441\u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0438\u0440\u0443\u0435\u043c \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0441 \u0431\u0430\u0437\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445. \u041c\u044b \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043d\u043e\u0432\u0443\u044e \u043f\u0430\u043f\u043a\u0443 app \u043f\u0440\u044f\u043c\u043e \u0432 \u043d\u0430\u0448\u0435\u0439 \u043a\u043e\u0440\u043d\u0435\u0432\u043e\u0439 \u043f\u0430\u043f\u043a\u0435, \u0438 \u0442\u0430\u043c \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0444\u0430\u0439\u043b <code>db.config.js<\/code> \u0432 \u043f\u0430\u043f\u043a\u0435 <code>config<\/code>, \u0432\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0441 \u0442\u0430\u043a\u0438\u043c \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435\u043c, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u0432\u0430\u0448\u0438\u0445 \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043a \u0432 MySQLWorkBranch. \u0412 \u043c\u043e\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0444\u0430\u0439\u043b \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0432\u043e\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"javascript\">  module.exports = {     HOST: &quot;localhost&quot;,     USER: &quot;pavel&quot;,     PASSWORD: &quot;&quot;,     DB: &quot;TODO&quot;   }; <\/code><\/pre>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043f\u0430\u043f\u043a\u0443 \u0434\u043b\u044f \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u043d\u0430\u0448\u0438\u0445 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 <i>app\/mode<\/i>, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043c\u044b \u043f\u043e\u0442\u043e\u043c \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043c\u043e\u0434\u0435\u043b\u044c:<\/p>\n<pre><code class=\"plaintext\">  const mysql = require(&quot;mysql&quot;);   const dbConfig = require(&quot;..\/config\/db.config.js&quot;);      \/\/ \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0441 \u043d\u0430\u0448\u0435\u0439 \u0431\u0430\u0437\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445   const connection = mysql.createConnection({     host: dbConfig.HOST,     user: dbConfig.USER,     password: dbConfig.PASSWORD,     database: dbConfig.DB   });      \/\/ \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u043d\u0430\u0448\u0435 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0441 \u0431\u0430\u0437\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445   connection.connect(err =&gt; {     if (err) throw error;     console.log(&quot;\u0443\u0441\u043f\u0435\u0448\u043d\u043e \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u043e \u0441 \u0431\u0430\u0437\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445&quot;);   });    module.exports = connection;    \/\/\u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u043d\u0430\u0448\u0435 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 <\/code><\/pre>\n<h5> \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u041c\u043e\u0434\u0435\u043b\u044c <\/h5>\n<p>   \u0412 \u043f\u0430\u043f\u043a\u0435 <code>model<\/code>, \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0444\u0430\u0439\u043b, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f <code>deal.model.js<\/code>. \u0415\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u0432\u043e\u043f\u0440\u043e\u0441, \u0447\u0442\u043e \u0436\u0435 \u0442\u0430\u043a\u043e\u0435 \u0432\u043e\u043e\u0431\u0449\u0435 \u043c\u043e\u0434\u0435\u043b\u044c, \u0432\u0430\u043c \u0441\u0442\u043e\u0438\u0442 \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0441\u0442\u0430\u0442\u044c\u044e \u0432\u0440\u043e\u0434\u0435 <a href=\"https:\/\/metanit.com\/web\/nodejs\/7.2.php\">\u044d\u0442\u043e\u0439<\/a> \u0438 \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u044c\u0441\u044f \u0441 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u043e\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f MVC. \u042f \u0441\u043e\u0431\u0438\u0440\u0430\u044e\u0441\u044c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0434\u043b\u044f Deal \u043e\u0431\u044a\u0435\u043a\u0442\u0430, \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c connection \u0434\u043b\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 CRUD \u0444\u0443\u043d\u043a\u0446\u0438\u0439:<\/p>\n<ul>\n<li> \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043d\u043e\u0432\u043e\u0433\u043e \u0434\u0435\u043b\u0430<\/li>\n<li> \u043d\u0430\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u0435 \u0434\u0435\u043b\u0430 \u043f\u043e id<\/li>\n<li> \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0432\u0441\u0435\u0445 \u0434\u0435\u043b<\/li>\n<li> \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0442\u044c \u043d\u0430\u0448\u0435 \u0434\u0435\u043b\u043e \u043f\u043e id<\/li>\n<li> \u0423\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u0434\u0435\u043b\u0430 \u043f\u043e id<\/li>\n<li> \u043f\u043e\u043b\u043d\u043e\u0435 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u0432\u0441\u0435\u0445 \u0434\u0435\u043b<\/li>\n<\/ul>\n<p>  \u0418\u0442\u043e\u0433\u043e, \u043d\u0430\u043c \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0437\u0430\u043d\u044f\u0442\u044c\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c\u0438 \u0434\u0435\u043b\u0430\u043c\u0438:<\/p>\n<pre><code class=\"javascript\">  \/\/ \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u043d\u0430\u0448\u0435\u0433\u043e \u0434\u0435\u043b\u0430   const Deal = function(deal) {     this.text = deal.text;   };   \/\/\u0443 \u043d\u0430\u0448\u0435\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u0431\u0443\u0434\u0443\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043c\u043e\u0436\u043d\u043e \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u0442\u044c \u0432\u0441\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 CRUD, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u044b\u043b\u0438 \u043e\u0437\u0432\u0443\u0447\u0435\u043d\u044b \u0432 \u043d\u0430\u0447\u0430\u043b\u0435 \u0441\u0442\u0430\u0442\u044c\u0438:   Deal.create = (newDeal, result) =&gt; {     sql.query(&quot;INSERT INTO TODO SET ?&quot;, newDeal, (err, res) =&gt; {       \/\/\u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u0432\u0441\u0442\u0430\u0432\u043a\u0438 \u0438\u0437 SQL       if (err) {         console.log(&quot;error: &quot;, err);         result(err, null);         \/\/\u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0431\u0435\u0434\u043d\u0430\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043e\u0448\u0438\u0431\u043e\u043a, \u043d\u043e \u043d\u0430 \u043f\u0435\u0440\u0432\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u0445\u0432\u0430\u0442\u0438\u0442         return;       }          console.log(&quot;\u0414\u0435\u043b\u043e \u0441\u0434\u0435\u043b\u0430\u043d\u043e&quot;, { id: res.insertId, ...newDeal });       result(null, { id: res.insertId, ...newDeal });     });   };  <\/code><\/pre>\n<p>  \u041e\u0441\u0442\u0430\u043b\u044c\u043d\u0443\u044e \u0447\u0430\u0441\u0442\u044c \u043a\u043e\u0434\u0430 \u044f \u0440\u0430\u0437\u043c\u0435\u0449\u0443 \u0432 spoiler, \u043f\u043e\u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u043d\u0435 \u0432\u0438\u0436\u0443 \u0441\u043c\u044b\u0441\u043b\u0430 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442\u044c \u0435\u0433\u043e \u0432\u0435\u0441\u044c, \u0432\u0435\u0434\u044c \u0442\u0430\u043c \u043f\u043e \u0441\u0443\u0442\u0438 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u0435\u0442\u0441\u044f \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u043a\u043e\u0434\u0430, \u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e sql \u2014 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b:<\/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\"> Deal.findById = (dealId, result) =&gt; {<br \/>   sql.query(`SELECT * FROM TODO WHERE id = ${dealId}`, (err, res) =&gt; {<br \/>   if (err) {<br \/>   console.log(\u00aberror: \u00bb, err);<br \/>   result(err, null);<br \/>   return;<br \/>   }<\/p>\n<p>   if (res.length) {<br \/>   console.log(\u00ab\u043d\u0430\u0439\u0434\u0435\u043d\u043e \u0434\u0435\u043b\u043e: \u00bb, res[0]);<br \/>   result(null, res[0]);<br \/>   return;<br \/>   }<\/p>\n<p>   \/\/ \u043a\u043e\u0433\u0434\u0430 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u043d\u0430\u0439\u0442\u0438<br \/>   result({ kind: \u00abnot_found\u00bb }, null);<br \/>   });<br \/>   };<\/p>\n<p>   Deal.getAll = result =&gt; {<br \/>   sql.query(\u00abSELECT * FROM TODO\u00bb, (err, res) =&gt; {<br \/>   if (err) {<br \/>   console.log(\u00aberror: \u00bb, err);<br \/>   result(null, err);<br \/>   return;<br \/>   }<\/p>\n<p>   console.log(\u00abdeals: \u00bb, res);<br \/>   result(null, res);<br \/>   });<br \/>   };<\/p>\n<p>   Deal.updateById = (id, deal, result) =&gt; {<br \/>   sql.query(<br \/>   \u00abUPDATE TODO SET text =? WHERE id = ?\u00bb,<br \/>   [deal.text, id],<br \/>   (err, res) =&gt; {<br \/>   if (err) {<br \/>   console.log(\u00aberror: \u00bb, err);<br \/>   result(null, err);<br \/>   return;<br \/>   }<\/p>\n<p>   if (res.affectedRows == 0) {<br \/>   result({ kind: \u00abnot_found\u00bb }, null);<br \/>   return;<br \/>   }<\/p>\n<p>   console.log(\u00ab\u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u043e \u0434\u0435\u043b\u043e \u00bb, { id: id, &#8230;deal });<br \/>   result(null, { id: id, &#8230;deal });<br \/>   }<br \/>   );<br \/>   };<\/p>\n<p>   Deal.remove = (id, result) =&gt; {<br \/>   sql.query(\u00abDELETE FROM TODO WHERE id = ?\u00bb, id, (err, res) =&gt; {<br \/>   if (err) {<br \/>   console.log(\u00aberror: \u00bb, err);<br \/>   result(null, err);<br \/>   return;<br \/>   }<\/p>\n<p>   if (res.affectedRows == 0) {<br \/>   \/\/ \u0435\u0441\u043b\u0438 \u0434\u0435\u043b\u043e \u043d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043f\u043e id<br \/>   result({ kind: \u00abnot_found\u00bb }, null);<br \/>   return;<br \/>   }<br \/>   console.log(\u00ab\u0423\u0434\u0430\u043b\u0435\u043d \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0441 \u00bb, id);<br \/>   result(null, res);<br \/>   });<br \/>   };<\/p>\n<p>   Deal.removeAll = result =&gt; {<br \/>   sql.query(\u00abDELETE FROM TODO\u00bb, (err, res) =&gt; {<br \/>   if (err) {<br \/>   console.log(\u00aberror: \u00bb, err);<br \/>   result(null, err);<br \/>   return;<br \/>   }<\/p>\n<p>   console.log(`deleted ${res.affectedRows} deals`);<br \/>   result(null, res);<br \/>   });<br \/>   };<\/p><\/div>\n<\/div>\n<p>   \u041d\u0430 \u044d\u0442\u043e\u043c \u043f\u043e\u043a\u0430 \u0432\u0441\u0435. \u041d\u0430 \u043f\u043e\u0434\u0445\u043e\u0434\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043c\u044b \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043c \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0431\u044d\u043a\u0430 \u0438 \u043f\u0440\u0438\u043c\u0435\u043c\u0441\u044f \u0437\u0430 \u0435\u0433\u043e \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435. \u0418 \u043f\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<ul>\n<li> <a href=\"https:\/\/habr.com\/ru\/company\/ruvds\/blog\/414079\/\">\u041e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0440\u0430\u0431\u043e\u0442\u044b \u0438 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u0433\u043e \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430 express.js<\/a><\/li>\n<li> <a href=\"http:\/\/g2pc1.bu.edu\/~qzpeng\/manual\/MySQL%20Commands.htm\">\u041e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u044b MySQL<\/a><\/li>\n<li> <a href=\"https:\/\/medium.com\/@jen_strong\/the-request-response-cycle-of-the-web-1b7e206e9047\"> \u041d\u0435\u043c\u043d\u043e\u0433\u043e \u043e \u0446\u0438\u043a\u043b\u0435 HTTP request\/response<\/a> <\/li>\n<li> <a href=\"https:\/\/frontender.info\/es6-in-depth-arrow-functions\/\"> \u041d\u0435\u043c\u043d\u043e\u0433\u043e \u043e \u0441\u0442\u0440\u0435\u043b\u043e\u0447\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u0445, \u0435\u0441\u043b\u0438 \u0432\u044b \u0441\u043e\u0432\u0441\u0435\u043c \u043d\u043e\u0432\u0438\u0447\u043e\u043a<\/a><\/li>\n<\/ul>\n<\/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\/491408\/\"> https:\/\/habr.com\/ru\/company\/otus\/blog\/491408\/<\/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\/491408\/\"><b><i>\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\/NZUM\/\">\u00abFullstack \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a JavaScript<\/a>\u00bb, \u0445\u043e\u0442\u0438\u043c \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u043c \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u043e\u043c, \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.<\/i><\/b><\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/9w\/az\/vb\/9wazvb3h8u0o1gjvijjntbhrkgk.png\"><\/p>\n<p>  Express \u043e\u0434\u0438\u043d \u0438\u0437 \u0441\u0430\u043c\u044b\u0445 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u0432\u0435\u0431-\u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0440\u043e\u0443\u0442\u0438\u043d\u0433, \u043c\u0438\u0434\u0434\u043b\u0432\u0435\u0439\u0440\u0441 \u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u0432. \u0414\u0435\u043b\u0430\u0442\u044c \u0431\u044d\u043a\u0435\u043d\u0434 \u043d\u0430 Node.js \u0431\u0435\u0437 Express \u0432 2020 \u0433\u043e\u0434\u0443 \u2014 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0441\u0442\u0440\u0430\u043d\u043d\u043e\u0435 \u0437\u0430\u043d\u044f\u0442\u0438\u0435, \u0432\u0435\u0434\u044c Express \u0434\u0435-\u0444\u0430\u043a\u0442\u043e \u2014 \u043a\u0430\u0440\u043a\u0430\u0441 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0432\u0435\u0431-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0430 Node.js. <br \/>  \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u043c\u044b \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043d\u0435\u0441\u043b\u043e\u0436\u043d\u043e\u0435 CRUD API \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 MySQL. \u041e\u043f\u044b\u0442\u043d\u044b\u0439 \u0432 Node.js \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u044c \u0441\u043f\u0440\u043e\u0441\u0438\u0442, \u0430 \u0433\u0434\u0435 \u0436\u0435 MongoDB, \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c Node.js \u043e\u0431\u044b\u0447\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u0441\u044f \u0432 \u043f\u0430\u0440\u0435 \u043d\u043e, \u0441\u043a\u0430\u0436\u0443 \u0441\u0440\u0430\u0437\u0443, \u044d\u0442\u043e \u0441\u0442\u0430\u0442\u044c\u044f \u0431\u043e\u043b\u044c\u0448\u0435 \u0434\u043b\u044f PHP \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0445\u043e\u0442\u044f\u0442 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u043e\u0442\u0440\u043e\u0433\u0430\u0442\u044c Node.js, \u0438 \u0447\u0442\u043e\u0431\u044b \u0441\u043c\u044f\u0433\u0447\u0438\u0442\u044c \u043f\u0435\u0440\u0435\u0445\u043e\u0434 \u0432 \u043d\u043e\u0432\u0443\u044e \u044d\u043a\u043e\u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u043c\u044b \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f MySQL. API \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u043d\u0435\u0441\u043b\u043e\u0436\u043d\u043e\u0433\u043e Todo \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u043d\u0430 \u0442\u043e\u0442 \u0441\u043b\u0443\u0447\u0430\u0439, \u0435\u0441\u043b\u0438 \u043a\u0442\u043e-\u0442\u043e \u0437\u0430\u0445\u043e\u0447\u0435\u0442 \u043a \u0441\u0432\u043e\u0435\u0439 todo (\u0438 \u0434\u0430\u0436\u0435 \u043d\u0435\u0432\u0430\u0436\u043d\u043e, \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u0439 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e React \u0438\u043b\u0438 \u043d\u0435\u0442), \u043f\u0440\u0438\u0441\u043e\u0435\u0434\u0438\u043d\u0438\u0442\u044c \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0431\u044d\u043a\u0430 \u0438 \u043f\u043e\u0438\u0433\u0440\u0430\u0442\u044c \u0441 \u043d\u0438\u043c.<\/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-299772","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/299772","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=299772"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/299772\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=299772"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=299772"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=299772"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}