{"id":323618,"date":"2021-05-23T15:00:48","date_gmt":"2021-05-23T15:00:48","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=323618"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=323618","title":{"rendered":"\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 ECMAScript-\u043c\u043e\u0434\u0443\u043b\u0435\u0439 \u0432 Node.js"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\">ECMAScript-\u043c\u043e\u0434\u0443\u043b\u0438 (\u043a\u0440\u0430\u0442\u043a\u043e \u0438\u0445 \u043d\u0430\u0437\u044b\u0432\u0430\u044e\u0442 ES-\u043c\u043e\u0434\u0443\u043b\u044f\u043c\u0438) \u2014 \u044d\u0442\u043e \u043c\u043e\u0434\u0443\u043b\u0438, \u0444\u043e\u0440\u043c\u0430\u0442 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043e\u043f\u0438\u0441\u0430\u043d \u0432 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u0435 ECMAScript, \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 <code>import<\/code> \u0438 <code>export<\/code>:<\/p>\n<pre><code class=\"javascript\">\/\/ ECMAScript-\u043c\u043e\u0434\u0443\u043b\u044c  \/\/ \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f import import myFunc from '.\/my-func';  \/\/\u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f export export myOtherFunc(param) { \u00a0\u00a0const result = myFunc(param); \u00a0\u00a0\/\/ .... \u00a0\u00a0return otherResult; } <\/code><\/pre>\n<p>  \u0412 Node.js, \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 \u0432\u0435\u0440\u0441\u0438\u0438 13.2.0, \u0438\u043c\u0435\u0435\u0442\u0441\u044f \u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u0430\u044f \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 ES-\u043c\u043e\u0434\u0443\u043b\u0435\u0439.<\/p>\n<p>  <a href=\"https:\/\/habr.com\/ru\/company\/ruvds\/blog\/556744\/\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/kx\/pi\/80\/kxpi80bx-pfp4sm_iz52k5tacrk.png\"><\/a><\/p>\n<p>  \u042d\u0442\u043e\u0442 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b \u043f\u043e\u0441\u0432\u044f\u0449\u0451\u043d \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u044f\u043c \u0440\u0430\u0431\u043e\u0442\u044b \u0441 ES-\u043c\u043e\u0434\u0443\u043b\u044f\u043c\u0438 \u0432 Node.js.<br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<h2><font color=\"#3AC1EF\">1. \u0423\u0441\u043b\u043e\u0432\u0438\u044f, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 ES-\u043c\u043e\u0434\u0443\u043b\u044f\u043c\u0438 \u0432 Node.js<\/font><\/h2>\n<p>  \u041d\u0430 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435 Node.js \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u043c\u043e\u0434\u0443\u043b\u0438 \u0444\u043e\u0440\u043c\u0430\u0442\u0430 <a href=\"https:\/\/nodejs.org\/docs\/latest\/api\/modules.html#modules_modules_commonjs_modules\">CommonJS<\/a>. \u0414\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0430 \u0441\u043c\u043e\u0433\u043b\u0430 \u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c ES-\u043c\u043e\u0434\u0443\u043b\u0438, \u043d\u0443\u0436\u043d\u043e \u043a\u043e\u0435-\u0447\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c.<\/p>\n<p>  \u0410 \u0438\u043c\u0435\u043d\u043d\u043e, Node.js \u0441\u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f ES-\u043c\u043e\u0434\u0443\u043b\u044f\u043c\u0438 \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445:<\/p>\n<ul>\n<li>\u0415\u0441\u043b\u0438 \u0444\u0430\u0439\u043b \u043c\u043e\u0434\u0443\u043b\u044f \u0438\u043c\u0435\u0435\u0442 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 <code>.mjs<\/code>.<\/li>\n<li>\u0418\u043b\u0438 \u0435\u0441\u043b\u0438 \u0432 <code>package.json<\/code> \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0435\u0439 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0439 \u043f\u0430\u043f\u043a\u0438 \u043c\u043e\u0434\u0443\u043b\u044f \u0438\u043c\u0435\u0435\u0442\u0441\u044f \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f <code>{ \u00abtype\u00bb: \u00abmodule\u00bb }<\/code>.<\/li>\n<li>\u0418\u043b\u0438 \u0435\u0441\u043b\u0438 \u043f\u0440\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0435 Node.js \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0444\u043b\u0430\u0433 <code>--input-type=module<\/code>, \u0438 \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043a\u043e\u0434 \u043c\u043e\u0434\u0443\u043b\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u0442\u0441\u044f \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435 \u0432 \u0432\u0438\u0434\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 <code>--eval=&quot;&lt;module-code&gt;&quot;<\/code>, \u0438\u043b\u0438 \u043f\u043e\u0441\u0442\u0443\u043f\u0430\u0435\u0442 \u0438\u0437 <code>STDIN<\/code>.<\/li>\n<\/ul>\n<p>  \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0435\u0440\u0432\u044b\u0435 \u0434\u0432\u0430 \u0441\u043f\u043e\u0441\u043e\u0431\u0430 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043c\u043e\u0434\u0443\u043b\u044f\u043c\u0438 (\u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 .mjs-\u0444\u0430\u0439\u043b\u043e\u0432 \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 <code>{ \u00abtype\u00bb: \u00abmodule\u00bb }<\/code> \u0432 <code>package.json<\/code>).<\/p>\n<h3><font color=\"#3AC1EF\">\u258d1.1. \u0420\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 \u0444\u0430\u0439\u043b\u043e\u0432 .mjs<\/font><\/h3>\n<p>  \u041b\u0435\u0433\u0447\u0435 \u0432\u0441\u0435\u0433\u043e \u0441\u043e\u043e\u0431\u0449\u0438\u0442\u044c Node.js \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u043d\u0435\u043a\u0438\u0439 \u0444\u0430\u0439\u043b \u043d\u0430\u0434\u043e \u0432\u043e\u0441\u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u043a\u0430\u043a ES-\u043c\u043e\u0434\u0443\u043b\u044c, \u043c\u043e\u0436\u043d\u043e, \u0434\u0430\u0432 \u044d\u0442\u043e\u043c\u0443 \u0444\u0430\u0439\u043b\u0443 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 <code>.mjs<\/code>.<\/p>\n<p>  \u041a\u043e\u0434 ES-\u043c\u043e\u0434\u0443\u043b\u044f, \u043f\u0440\u0438\u0432\u0435\u0434\u0451\u043d\u043d\u044b\u0439 \u043d\u0438\u0436\u0435, \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0432 \u0444\u0430\u0439\u043b\u0435 <code>month-from-date.mjs<\/code> (\u043e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 <code>.mjs<\/code>). \u041c\u043e\u0434\u0443\u043b\u044c \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>monthFromDate()<\/code>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043c\u0435\u0441\u044f\u0446\u0430 \u043f\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u043e\u0439 \u0434\u0430\u0442\u0435, \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u043e\u0439 \u0435\u0439.<\/p>\n<pre><code class=\"javascript\">\/\/ month-from-date.mjs (ES-\u043c\u043e\u0434\u0443\u043b\u044c)  const MONTHS = ['January', 'February', 'March','April', 'May', 'June',\u00a0 \u00a0\u00a0'July', 'August', 'September', 'October', 'November', 'December'];  export function monthFromDate(date) { \u00a0\u00a0if (!(date instanceof Date)) { \u00a0\u00a0\u00a0\u00a0date = new Date(date); \u00a0\u00a0} \u00a0\u00a0return MONTHS[date.getMonth()]; } <\/code><\/pre>\n<p>  \u0414\u0440\u0443\u0433\u043e\u0439 ES-\u043c\u043e\u0434\u0443\u043b\u044c, <code>month.mjs<\/code>, \u043f\u043e\u0445\u043e\u0436\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044e <code>import<\/code> \u0434\u043b\u044f \u0438\u043c\u043f\u043e\u0440\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>monthFromDate()<\/code> \u0438\u0437 \u043c\u043e\u0434\u0443\u043b\u044f <code>month-from-date.mjs<\/code>. \u042d\u0442\u043e\u0442 \u043c\u043e\u0434\u0443\u043b\u044c, \u043a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u043f\u0440\u0438\u0451\u043c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0438\u0437 \u043a\u043e\u043c\u0430\u043d\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438, \u0432\u044b\u0432\u043e\u0434\u044f \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043c\u0435\u0441\u044f\u0446\u0430 \u043f\u043e\u0441\u043b\u0435 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u043e\u0439 \u0435\u043c\u0443 \u0434\u0430\u0442\u044b:<\/p>\n<pre><code class=\"javascript\">\/\/ month.mjs (ES-\u043c\u043e\u0434\u0443\u043b\u044c)  import { monthFromDate } from '.\/month-from-date.mjs';  const dateString = process.argv[2] ?? null;  console.log(monthFromDate(dateString)); <\/code><\/pre>\n<p>  \u042d\u0442\u043e \u2014 \u0432\u0441\u0451 \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0434\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f ES-\u043c\u043e\u0434\u0443\u043b\u044f\u043c\u0438 \u0432 Node.js!<\/p>\n<p>  \u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c <code>month.mjs<\/code> \u0432 \u043a\u043e\u043c\u0430\u043d\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435:<\/p>\n<pre><code class=\"javascript\">node .\/month.mjs &quot;2022-02-01&quot; <\/code><\/pre>\n<p>  \u0412 \u043e\u0442\u0432\u0435\u0442 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0432\u0435\u0434\u0435\u043d\u043e \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043c\u0435\u0441\u044f\u0446\u0430 \u2014 <code>February<\/code>.<\/p>\n<p>  \u041f\u043e\u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441 \u044d\u0442\u0438\u043c \u0441\u043a\u0440\u0438\u043f\u0442\u043e\u043c \u043c\u043e\u0436\u043d\u043e <a href=\"https:\/\/codesandbox.io\/s\/mjs-extension-8cio7?file=\/month.mjs\">\u0437\u0434\u0435\u0441\u044c<\/a>.<\/p>\n<h3><font color=\"#3AC1EF\">\u258d1.2. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 { \u00abtype\u00bb: \u00abmodule\u00bb } \u0432 package.json<\/font><\/h3>\n<p>  \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e Node.js \u0432\u043e\u0441\u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0444\u0430\u0439\u043b\u044b \u0441 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435\u043c <code>.js<\/code> \u043a\u0430\u043a CommonJS-\u043c\u043e\u0434\u0443\u043b\u0438. \u0414\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u0442\u0430\u043a\u0438\u0435 \u0444\u0430\u0439\u043b\u044b \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u043b\u0438 \u0431\u044b \u0434\u043b\u044f Node.js \u043a\u0430\u043a ES-\u043c\u043e\u0434\u0443\u043b\u0438, \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0432 \u043f\u043e\u043b\u0435 <code>type<\/code> \u0444\u0430\u0439\u043b\u0430 <code>package.json<\/code> \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>module<\/code>:<\/p>\n<pre><code class=\"javascript\">{ \u00a0\u00a0&quot;name&quot;: &quot;my-app&quot;, \u00a0\u00a0&quot;version&quot;: &quot;1.0.0&quot;, \u00a0\u00a0&quot;type&quot;: &quot;module&quot;, \u00a0\u00a0\/\/ ... } <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0432\u0441\u0435 .js-\u0444\u0430\u0439\u043b\u044b \u0432 \u043f\u0430\u043f\u043a\u0435, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0435\u0439 \u0442\u0430\u043a\u043e\u0439 <code>package.json<\/code>, \u0431\u0443\u0434\u0443\u0442 \u0432\u043e\u0441\u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c\u0441\u044f \u043a\u0430\u043a ES-\u043c\u043e\u0434\u0443\u043b\u0438.<\/p>\n<p>  \u041f\u0435\u0440\u0435\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u043d\u0430\u0448 \u043f\u0440\u0438\u043c\u0435\u0440. \u0410 \u0438\u043c\u0435\u043d\u043d\u043e \u2014 \u043f\u0435\u0440\u0435\u0438\u043c\u0435\u043d\u0443\u0435\u043c <code>month-from-date.mjs<\/code> \u0432 <code>month-from-date.js<\/code>, \u0430 <code>month.mjs<\/code> \u0432 <code>month.js<\/code> (\u043d\u0435 \u0442\u0440\u043e\u0433\u0430\u044f \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 <code>import<\/code> \u0438 <code>export<\/code>). \u0417\u0430\u0442\u0435\u043c, \u0432 \u0444\u0430\u0439\u043b <code>package.json<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u0442\u043e\u0439 \u0436\u0435 \u043f\u0430\u043f\u043a\u0435, \u0447\u0442\u043e \u0438 \u044d\u0442\u0438 \u0444\u0430\u0439\u043b\u044b, \u0432\u043d\u0435\u0441\u0451\u043c \u0437\u0430\u043f\u0438\u0441\u044c <code>\u00abtype\u00bb: \u00abmodule\u00bb<\/code>. \u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e Node.js \u0431\u0443\u0434\u0435\u0442 \u0432\u043e\u0441\u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u043d\u0430\u0448\u0438 .js-\u0444\u0430\u0439\u043b\u044b \u043a\u0430\u043a ES-\u043c\u043e\u0434\u0443\u043b\u0438.<\/p>\n<p>  \u041f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e, \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0432 \u0432 \u043a\u043e\u043c\u0430\u043d\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<pre><code class=\"javascript\">node .\/month.js &quot;2022-03-01&quot; <\/code><\/pre>\n<p>  \u0421\u0438\u0441\u0442\u0435\u043c\u0430 \u0432\u044b\u0434\u0430\u0441\u0442 <code>March<\/code>.<\/p>\n<p>  <a href=\"https:\/\/codesandbox.io\/s\/type-module-lcr0m?file=\/month.js\">\u0412\u043e\u0442<\/a> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443 \u0441 \u0438\u043d\u0442\u0435\u0440\u0430\u043a\u0442\u0438\u0432\u043d\u044b\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u043c.<\/p>\n<h2><font color=\"#3AC1EF\">2. \u0418\u043c\u043f\u043e\u0440\u0442 ES-\u043c\u043e\u0434\u0443\u043b\u0435\u0439<\/font><\/h2>\n<p>  \u0421\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u2014 \u044d\u0442\u043e \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u043e\u0439 \u043b\u0438\u0442\u0435\u0440\u0430\u043b, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0439 \u043f\u0443\u0442\u044c \u043a \u0442\u043e\u043c\u0443 \u043c\u0435\u0441\u0442\u0443, \u043e\u0442\u043a\u0443\u0434\u0430 \u043d\u0443\u0436\u043d\u043e \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043c\u043e\u0434\u0443\u043b\u044c.<\/p>\n<p>  \u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043a\u043e\u0434\u0430 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u043e\u043c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u0442\u0440\u043e\u043a\u0430 <code>path<\/code>:<\/p>\n<pre><code class=\"javascript\">\/\/ 'path' - \u044d\u0442\u043e \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 import module from 'path'; <\/code><\/pre>\n<p>  \u0412 Node.js \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0442\u0440\u0438 \u0432\u0438\u0434\u0430 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u043e\u0432: \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435, \u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u0438 \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u044b\u0435<\/p>\n<h3><font color=\"#3AC1EF\">\u258d2.1. \u041e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u044b<\/font><\/h3>\n<p>  \u0418\u043c\u043f\u043e\u0440\u0442 \u043c\u043e\u0434\u0443\u043b\u044f \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0430 \u043f\u0440\u0438\u0432\u0435\u0434\u0451\u0442 \u043a \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u044e \u043f\u0443\u0442\u0438 \u043a \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c\u043e\u043c\u0443 \u043c\u043e\u0434\u0443\u043b\u044e \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e (\u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u044e\u0449\u0435\u0433\u043e) \u043c\u043e\u0434\u0443\u043b\u044f. \u041e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u044b \u043e\u0431\u044b\u0447\u043d\u043e \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0442\u0441\u044f \u0441 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 <code>'.'<\/code>, <code>'..'<\/code> \u0438\u043b\u0438 <code>'.\/'<\/code>:<\/p>\n<pre><code class=\"javascript\">\/\/ \u041e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u044b: import module1 from '.\/module1.js'; import module2 from '..\/folder\/module2.mjs'; <\/code><\/pre>\n<p>  \u041f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u043e\u0432 \u043d\u0443\u0436\u043d\u043e \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 \u0444\u0430\u0439\u043b\u0430 (<code>.js<\/code>, <code>.mjs<\/code> \u0438 \u0442\u0430\u043a \u0434\u0430\u043b\u0435\u0435).<\/p>\n<h3><font color=\"#3AC1EF\">\u258d2.2. \u041f\u0440\u043e\u0441\u0442\u044b\u0435 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u044b<\/font><\/h3>\n<p>  \u041f\u0440\u043e\u0441\u0442\u043e\u0439 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u0441 \u0438\u043c\u0435\u043d\u0438 \u043c\u043e\u0434\u0443\u043b\u044f (\u0442\u043e \u0435\u0441\u0442\u044c \u2014 \u0443 \u043d\u0435\u0433\u043e \u0432 \u043d\u0430\u0447\u0430\u043b\u0435 \u043d\u0435\u0442 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 <code>'.'<\/code>, <code>'.\/'<\/code>, <code>'..'<\/code>, <code>'\/'<\/code>) \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0438\u043c\u043f\u043e\u0440\u0442\u0430 \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0445 \u043c\u043e\u0434\u0443\u043b\u0435\u0439 Node.js \u0438\u043b\u0438 \u043c\u043e\u0434\u0443\u043b\u0435\u0439 \u0438\u0437 \u043f\u0430\u043f\u043a\u0438 <code>node_modules<\/code>.<\/p>\n<p>  \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 \u0432 <code>node_modules<\/code> \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d \u043f\u0430\u043a\u0435\u0442 <code>lodash-es<\/code>, \u0442\u043e \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e, \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0432\u0448\u0438\u0441\u044c \u043f\u0440\u043e\u0441\u0442\u044b\u043c \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u043e\u043c:<\/p>\n<pre><code class=\"javascript\">\/\/ \u041f\u0440\u043e\u0441\u0442\u044b\u0435 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u044b: import lodash from 'lodash-es'; import intersection from 'lodash-es\/intersection'; <\/code><\/pre>\n<p>  \u041f\u0440\u043e\u0441\u0442\u044b\u0435 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u044b \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f \u0438 \u043f\u0440\u0438 \u0438\u043c\u043f\u043e\u0440\u0442\u0435 \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0445 \u043c\u043e\u0434\u0443\u043b\u0435\u0439 Node.js:<\/p>\n<pre><code class=\"javascript\">import fs from 'fs'; <\/code><\/pre>\n<p>  <\/p>\n<h3><font color=\"#3AC1EF\">\u258d2.3. \u0410\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u044b\u0435 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u044b<\/font><\/h3>\n<p>  \u0410\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u044b\u0435 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0434\u043b\u044f \u0438\u043c\u043f\u043e\u0440\u0442\u0430 \u043c\u043e\u0434\u0443\u043b\u0435\u0439 \u0441 \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u0435\u043c \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u043e\u0433\u043e \u043f\u0443\u0442\u0438 \u043a \u043d\u0438\u043c:<\/p>\n<pre><code class=\"javascript\">\/\/ \u0410\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u044b\u0439 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440: import module from 'file:\/\/\/usr\/opt\/module.js'; <\/code><\/pre>\n<p>  \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u0432 \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u043e\u043c \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0435 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043f\u0440\u0435\u0444\u0438\u043a\u0441 <code>file:\/\/<\/code>.<\/p>\n<h2><font color=\"#3AC1EF\">3. \u0414\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0438\u043c\u043f\u043e\u0440\u0442 \u043c\u043e\u0434\u0443\u043b\u0435\u0439<\/font><\/h2>\n<p>  \u0421\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u0438\u043c\u043f\u043e\u0440\u0442\u0430 ES-\u043c\u043e\u0434\u0443\u043b\u0435\u0439 \u0432\u0441\u0435\u0433\u0434\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u043a\u043e\u0434 \u043c\u043e\u0434\u0443\u043b\u044f, \u0443\u043f\u043e\u043c\u044f\u043d\u0443\u0442\u043e\u0433\u043e \u0432 \u043a\u043e\u043c\u0430\u043d\u0434\u0435 \u0432\u0438\u0434\u0430 <code>import module from 'path'<\/code>, \u0438 \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u0442 \u044d\u0442\u043e\u0442 \u043c\u043e\u0434\u0443\u043b\u044c. \u0414\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u044d\u0442\u043e \u0432\u043d\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0442\u043e\u0433\u043e, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043b\u0438 \u0432 \u043a\u043e\u0434\u0435 \u044d\u0442\u043e\u0442 \u043c\u043e\u0434\u0443\u043b\u044c \u0438\u043b\u0438 \u043d\u0435\u0442.<\/p>\n<p>  \u0418\u043d\u043e\u0433\u0434\u0430 \u0431\u044b\u0432\u0430\u0435\u0442 \u0442\u0430\u043a, \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043c\u043e\u0434\u0443\u043b\u044c \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438. \u0412 \u0442\u0430\u043a\u0438\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u043c\u043e\u0436\u043d\u043e \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 \u0432\u0438\u0434\u0430 <code>import('.\/path-to-module')<\/code>:<\/p>\n<pre><code class=\"javascript\">async function loadModule() { \u00a0\u00a0const {\u00a0 \u00a0\u00a0\u00a0\u00a0default: defaultComponent,\u00a0 \u00a0\u00a0\u00a0\u00a0component1\u00a0 \u00a0\u00a0} = await import('.\/path-to-module'); \u00a0\u00a0\/\/ ... }  loadModule(); <\/code><\/pre>\n<p>  \u041a\u043e\u043c\u0430\u043d\u0434\u0430 <code>import('.\/path-to-module')<\/code> \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u0442 \u043c\u043e\u0434\u0443\u043b\u044c \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043f\u0440\u043e\u043c\u0438\u0441, \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u043c \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u043c\u043e\u0434\u0443\u043b\u044f. \u0421\u0432\u043e\u0439\u0441\u0442\u0432\u043e <code>default<\/code> \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0438\u043c\u043f\u043e\u0440\u0442\u0430, \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u043e\u0433\u043e \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e, \u0430 \u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0438\u043c\u043f\u043e\u0440\u0442\u044b \u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0432 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430\u0445 \u0441 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u043c\u0438 \u0438\u043c\u0435\u043d\u0430\u043c\u0438.<\/p>\n<p>  \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u043c\u043e\u0434\u0443\u043b\u044c <code>month-from-date.js<\/code> \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u043b\u0441\u044f \u0431\u044b \u0432 \u0441\u043a\u0440\u0438\u043f\u0442\u0435 <code>month.js<\/code> \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c, \u043f\u0440\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0435 \u0441\u043a\u0440\u0438\u043f\u0442\u0430, \u043f\u0435\u0440\u0435\u0434\u0430\u043b \u0435\u043c\u0443 \u0434\u0430\u0442\u0443:<\/p>\n<pre><code class=\"javascript\">\/\/ month.js (ES-\u043c\u043e\u0434\u0443\u043b\u044c)  const dateString = process.argv[2] ?? null;  if (dateString === null) { \u00a0\u00a0console.log('Please indicate date argument'); } else { \u00a0\u00a0(async function() { \u00a0\u00a0\u00a0\u00a0const { monthFromDate } = await import('.\/month-from-date.js'); \u00a0\u00a0\u00a0\u00a0console.log(monthFromDate(dateString)); \u00a0\u00a0})(); } <\/code><\/pre>\n<p>  \u041a\u043e\u043c\u0430\u043d\u0434\u0430 <code>const { monthFromDate } = await import('.\/month-from-date.mjs')<\/code> \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0443 \u043c\u043e\u0434\u0443\u043b\u044f \u0438 \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u0435\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0430 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u0435 \u0441 \u0442\u0435\u043c \u0436\u0435 \u0438\u043c\u0435\u043d\u0435\u043c, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0438\u043c\u0435\u0435\u0442 \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f.<\/p>\n<p>  \u0417\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u0432 \u043a\u043e\u043c\u0430\u043d\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<pre><code class=\"javascript\">node .\/month.js &quot;2022-04-01&quot; <\/code><\/pre>\n<p>  \u0421\u043a\u0440\u0438\u043f\u0442 \u0432\u044b\u0432\u0435\u0434\u0435\u0442 <code>April<\/code>.<\/p>\n<p>  \u041f\u043e\u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441 \u043a\u043e\u0434\u043e\u043c \u043c\u043e\u0436\u043d\u043e <a href=\"https:\/\/codesandbox.io\/s\/dynamic-t15zl?file=\/month.js\">\u0437\u0434\u0435\u0441\u044c<\/a>.<\/p>\n<h2><font color=\"#3AC1EF\">4. \u0421\u043e\u0432\u043c\u0435\u0441\u0442\u043d\u043e\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043c\u043e\u0434\u0443\u043b\u0435\u0439 \u0440\u0430\u0437\u043d\u044b\u0445 \u0444\u043e\u0440\u043c\u0430\u0442\u043e\u0432<\/font><\/h2>\n<p>  \u0420\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u043c\u043e\u0436\u0435\u0442 \u043e\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f \u0432 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438, \u043a\u043e\u0433\u0434\u0430 \u0435\u043c\u0443 \u043d\u0443\u0436\u043d\u043e \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c CommonJS-\u043c\u043e\u0434\u0443\u043b\u044c \u0432 ES-\u043c\u043e\u0434\u0443\u043b\u044c, \u0438\u043b\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043e\u0431\u0440\u0430\u0442\u043d\u0443\u044e \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0443.<\/p>\n<p>  \u041a \u0441\u0447\u0430\u0441\u0442\u044c\u044e, Node.js \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u044b \u0438\u043c\u043f\u043e\u0440\u0442\u0430 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e, \u0432\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u0432 \u0441\u043e\u0441\u0442\u0430\u0432 ES-\u043c\u043e\u0434\u0443\u043b\u0435\u0439 CommonJS-\u043c\u043e\u0434\u0443\u043b\u0438:<\/p>\n<pre><code class=\"javascript\">\/\/ ES-\u043c\u043e\u0434\u0443\u043b\u044c  import defaultComponent from '.\/module.commonjs.js';  \/\/ \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f `defaultComponent`... <\/code><\/pre>\n<p>  \u041f\u0440\u0438 \u0438\u043c\u043f\u043e\u0440\u0442\u0435 CommonJS-\u043c\u043e\u0434\u0443\u043b\u044f \u0432 ES-\u043c\u043e\u0434\u0443\u043b\u0435 \u0442\u043e, \u0447\u0442\u043e \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043e \u0432 CommonJS-\u043c\u043e\u0434\u0443\u043b\u0435 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043a\u043e\u043c\u0430\u043d\u0434\u044b <code>module.exports<\/code>, \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0432 \u0438\u043c\u043f\u043e\u0440\u0442 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e. \u041f\u0440\u0430\u0432\u0434\u0430, \u043d\u0430\u0434\u043e \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0438\u043c\u043f\u043e\u0440\u0442\u044b \u0438\u0437 CommonJS-\u043c\u043e\u0434\u0443\u043b\u0435\u0439 \u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0442\u0441\u044f.<\/p>\n<p>  \u041e\u0434\u043d\u0430\u043a\u043e, \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>require()<\/code>, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0430\u044f \u0434\u043b\u044f \u0438\u043c\u043f\u043e\u0440\u0442\u0430 CommonJS-\u043c\u043e\u0434\u0443\u043b\u0435\u0439, \u043d\u0435 \u0443\u043c\u0435\u0435\u0442 \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c ES-\u043c\u043e\u0434\u0443\u043b\u0438. \u0412\u043c\u0435\u0441\u0442\u043e \u043d\u0435\u0451 \u0432 CommonJS-\u043c\u043e\u0434\u0443\u043b\u044f\u0445 \u043c\u043e\u0436\u043d\u043e, \u0434\u043b\u044f \u0438\u043c\u043f\u043e\u0440\u0442\u0430 ES-\u043c\u043e\u0434\u0443\u043b\u0435\u0439, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>import()<\/code>:<\/p>\n<pre><code class=\"javascript\">\/\/ CommonJS-\u043c\u043e\u0434\u0443\u043b\u044c  async function loadESModule() { \u00a0\u00a0const {\u00a0 \u00a0\u00a0\u00a0\u00a0default: defaultComponent,\u00a0 \u00a0\u00a0\u00a0\u00a0component1\u00a0 \u00a0\u00a0} = await import('.\/module.es.mjs'); \u00a0\u00a0\/\/ ... }  loadESModule(); <\/code><\/pre>\n<p>  \u042f \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e \u043d\u0430\u0441\u0442\u043e\u043b\u044c\u043a\u043e, \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u044d\u0442\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0432\u043e\u0437\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u043e\u0442 \u0441\u043c\u0435\u0448\u0438\u0432\u0430\u043d\u0438\u044f \u043c\u043e\u0434\u0443\u043b\u0435\u0439 \u0440\u0430\u0437\u043d\u044b\u0445 \u0444\u043e\u0440\u043c\u0430\u0442\u043e\u0432.<\/p>\n<h2><font color=\"#3AC1EF\">5. ES-\u043c\u043e\u0434\u0443\u043b\u0438 \u0438 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0435 Node.js<\/font><\/h2>\n<p>  \u0412 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438 ES-\u043c\u043e\u0434\u0443\u043b\u044f \u043d\u0435\u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438, \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u043d\u044b\u0435 \u0434\u043b\u044f CommonJS-\u043c\u043e\u0434\u0443\u043b\u0435\u0439. \u0421\u0440\u0435\u0434\u0438 \u043d\u0438\u0445 \u043c\u043e\u0436\u043d\u043e \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435:<\/p>\n<ul>\n<li>require()<\/li>\n<li>exports<\/li>\n<li>module.exports<\/li>\n<li>__dirname<\/li>\n<li>__filename<\/li>\n<\/ul>\n<p>  \u041d\u043e \u0434\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u043e\u0433\u043e \u043f\u0443\u0442\u0438 \u043a \u0442\u0435\u043a\u0443\u0449\u0435\u043c\u0443 \u043c\u043e\u0434\u0443\u043b\u044e \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e\u043c <code>import.meta.url<\/code>:<\/p>\n<pre><code class=\"javascript\">\/\/ ES-\u043c\u043e\u0434\u0443\u043b\u044c, \u043f\u0443\u0442\u044c \u043a \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043a\u0430\u043a &quot;\/usr\/opt\/module.mjs&quot;  console.log(import.meta.url); \/\/ &quot;file:\/\/\/usr\/opt\/module.mjs&quot; <\/code><\/pre>\n<p>  <\/p>\n<h2><font color=\"#3AC1EF\">6. \u0418\u0442\u043e\u0433\u0438<\/font><\/h2>\n<p>  Node.js \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 ES-\u043c\u043e\u0434\u0443\u043b\u044f\u043c\u0438 \u043f\u0440\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0438, \u0447\u0442\u043e \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435\u043c \u0444\u0430\u0439\u043b\u0430 \u043c\u043e\u0434\u0443\u043b\u044f \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f <code>.mjs<\/code>, \u0438\u043b\u0438 \u0432 \u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u0432 \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0435\u0439 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0439 \u043f\u0430\u043f\u043a\u0435 \u043c\u043e\u0434\u0443\u043b\u044f \u0438\u043c\u0435\u0435\u0442\u0441\u044f \u0444\u0430\u0439\u043b <code>package.json<\/code>, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0439 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044e <code>{ \u00abtype\u00bb: \u00abmodule\u00bb }<\/code>. \u0415\u0441\u043b\u0438 \u044d\u0442\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u0441\u043e\u0431\u043b\u044e\u0434\u0435\u043d\u044b \u2014 \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u0438\u043c\u0435\u044e\u0442\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043f\u043e \u0438\u043c\u043f\u043e\u0440\u0442\u0443 \u043c\u043e\u0434\u0443\u043b\u0435\u0439:<\/p>\n<ul>\n<li>\u041c\u043e\u0436\u043d\u043e \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u043f\u0443\u0442\u0451\u043c \u043a \u043c\u043e\u0434\u0443\u043b\u044e: <code>import module from '.\/module.js'<\/code>.<\/li>\n<li>\u041c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u044b\u0439 \u043f\u0443\u0442\u044c \u043a \u043c\u043e\u0434\u0443\u043b\u044e: <code>import module from 'file:\/\/\/abs\/path\/module.js'<\/code>.<\/li>\n<li>\u041c\u043e\u0436\u043d\u043e \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043c\u043e\u0434\u0443\u043b\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u043c\u0435\u044e\u0442\u0441\u044f \u0432 \u043f\u0430\u043f\u043a\u0435 <code>node_modules<\/code>: <code>import lodash from 'lodash-es'<\/code>.<\/li>\n<li>\u041c\u043e\u0436\u043d\u043e \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0435 \u043c\u043e\u0434\u0443\u043b\u0438 Node.js: <code>import fs from 'fs'<\/code>.<\/li>\n<li>\u041c\u043e\u0434\u0443\u043b\u0438 \u043c\u043e\u0436\u043d\u043e \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438, \u043f\u043e\u043b\u044c\u0437\u0443\u044f\u0441\u044c \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0435\u0439 \u0432\u0438\u0434\u0430 <code>import('.\/path-to-module')<\/code>.<\/li>\n<\/ul>\n<p>  \u0425\u043e\u0442\u044f \u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e\u0433\u043e \u0438 \u043d\u0435 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u0442\u0441\u044f, \u043d\u043e, \u0435\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e, CommonJS-\u043c\u043e\u0434\u0443\u043b\u0438 \u043c\u043e\u0436\u043d\u043e \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432 ES-\u043c\u043e\u0434\u0443\u043b\u0438, \u043f\u043e\u043b\u044c\u0437\u0443\u044f\u0441\u044c \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435\u043c \u0432\u0438\u0434\u0430 <code>import defaultImport from '.\/common.js'<\/code>. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u0442\u043e, \u0447\u0442\u043e \u0431\u044b\u043b\u043e \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043e \u0438\u0437 CommonJS-\u043c\u043e\u0434\u0443\u043b\u044f \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043a\u043e\u043c\u0430\u043d\u0434\u044b <code>module.exports<\/code>, \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0432 ES-\u043c\u043e\u0434\u0443\u043b\u0435 \u0432 \u0438\u043c\u043f\u043e\u0440\u0442 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e.<\/p>\n<p>  \u041f\u043b\u0430\u043d\u0438\u0440\u0443\u0435\u0442\u0435 \u043b\u0438 \u0432\u044b \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u043d\u0430 ES-\u043c\u043e\u0434\u0443\u043b\u0438 \u0432 \u0441\u0432\u043e\u0438\u0445 Node.js-\u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445?<\/p>\n<p>  <a href=\"https:\/\/habr.com\/ru\/company\/ruvds\/blog\/557204\/\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/ty\/b7\/fd\/tyb7fdkkt98xbfhc-jlqbuybdda.jpeg\"><\/a><br \/>  <a href=\"http:\/\/ruvds.com\/ru-rub?utm_source=habr&amp;utm_medium=article&amp;utm_campaign=avtor&amp;utm_content=ispolzovanie_ecmascript_modulej_v_node_js\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/ou\/g5\/kh\/oug5kh6sjydt9llengsiebnp40w.png\"><\/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\/ruvds\/blog\/556744\/\"> https:\/\/habr.com\/ru\/company\/ruvds\/blog\/556744\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\">ECMAScript-\u043c\u043e\u0434\u0443\u043b\u0438 (\u043a\u0440\u0430\u0442\u043a\u043e \u0438\u0445 \u043d\u0430\u0437\u044b\u0432\u0430\u044e\u0442 ES-\u043c\u043e\u0434\u0443\u043b\u044f\u043c\u0438) \u2014 \u044d\u0442\u043e \u043c\u043e\u0434\u0443\u043b\u0438, \u0444\u043e\u0440\u043c\u0430\u0442 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043e\u043f\u0438\u0441\u0430\u043d \u0432 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u0435 ECMAScript, \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 <code>import<\/code> \u0438 <code>export<\/code>:<\/p>\n<pre><code class=\"javascript\">\/\/ ECMAScript-\u043c\u043e\u0434\u0443\u043b\u044c  \/\/ \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f import import myFunc from '.\/my-func';  \/\/\u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f export export myOtherFunc(param) { \u00a0\u00a0const result = myFunc(param); \u00a0\u00a0\/\/ .... \u00a0\u00a0return otherResult; } <\/code><\/pre>\n<p>  \u0412 Node.js, \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 \u0432\u0435\u0440\u0441\u0438\u0438 13.2.0, \u0438\u043c\u0435\u0435\u0442\u0441\u044f \u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u0430\u044f \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 ES-\u043c\u043e\u0434\u0443\u043b\u0435\u0439.<\/p>\n<p>  <a href=\"https:\/\/habr.com\/ru\/company\/ruvds\/blog\/556744\/\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/kx\/pi\/80\/kxpi80bx-pfp4sm_iz52k5tacrk.png\"><\/a><\/p>\n<p>  \u042d\u0442\u043e\u0442 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b \u043f\u043e\u0441\u0432\u044f\u0449\u0451\u043d \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u044f\u043c \u0440\u0430\u0431\u043e\u0442\u044b \u0441 ES-\u043c\u043e\u0434\u0443\u043b\u044f\u043c\u0438 \u0432 Node.js.  <\/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-323618","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/323618","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=323618"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/323618\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=323618"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=323618"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=323618"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}