<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Kostiantyn</title>
    <description>The latest articles on DEV Community by Kostiantyn (@iconstyank).</description>
    <link>https://dev.to/iconstyank</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1442013%2Fb367cd00-82d9-4a64-9e84-159ddd92372d.png</url>
      <title>DEV Community: Kostiantyn</title>
      <link>https://dev.to/iconstyank</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/iconstyank"/>
    <language>en</language>
    <item>
      <title>How to show your app version in a Next.js (next js 14 app router)</title>
      <dc:creator>Kostiantyn</dc:creator>
      <pubDate>Mon, 22 Apr 2024 14:12:53 +0000</pubDate>
      <link>https://dev.to/iconstyank/how-to-show-your-app-version-in-a-nextjs-14-app-router-1k43</link>
      <guid>https://dev.to/iconstyank/how-to-show-your-app-version-in-a-nextjs-14-app-router-1k43</guid>
      <description>&lt;p&gt;There are only two ways to deal with JSON in ES modules today:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Read and parse JSON files yourself:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { readFile } from 'fs/promises';

const json = JSON.parse(
  await readFile(
    new URL('./some-file.json', import.meta.url)
  )
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Leverage the CommonJS require function to load JSON files:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { createRequire } from "module";

const require = createRequire(import.meta.url);
const data = require("./data.json");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With Next.js, it’s rather easy to use &lt;code&gt;next.config.js&lt;/code&gt; and &lt;code&gt;publicRuntimeConfig&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;My &lt;code&gt;footer.tsx&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import getConfig from 'next/config';

export default function Footer() {
  const { publicRuntimeConfig } = getConfig();
  return (
    &amp;lt;footer&amp;gt;
      ...
      &amp;lt;small&amp;gt;
        App Version: {publicRuntimeConfig?.version}
      &amp;lt;/small&amp;gt;
    &amp;lt;/footer&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And my &lt;code&gt;next.config.js&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { createRequire } from "module";

const require = createRequire(import.meta.url);
const json = require("./package.json");

const nextConfig = {
    ...
    publicRuntimeConfig: {
        version: json.version,
    },
};

export default nextConfig;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here you go!&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
