<?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: Atul Anand Oraon</title>
    <description>The latest articles on DEV Community by Atul Anand Oraon (@oatula).</description>
    <link>https://dev.to/oatula</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%2F1319777%2Fd2bddaf9-f403-4bb3-b3f1-0cc064f7368f.jpg</url>
      <title>DEV Community: Atul Anand Oraon</title>
      <link>https://dev.to/oatula</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/oatula"/>
    <language>en</language>
    <item>
      <title>Typescript extending types screws you at the most unexpected time</title>
      <dc:creator>Atul Anand Oraon</dc:creator>
      <pubDate>Thu, 23 Oct 2025 21:54:52 +0000</pubDate>
      <link>https://dev.to/oatula/typescript-extending-types-screws-you-at-the-most-unexpected-time-go2</link>
      <guid>https://dev.to/oatula/typescript-extending-types-screws-you-at-the-most-unexpected-time-go2</guid>
      <description>&lt;p&gt;So as we all get the issue with types. I too got it.&lt;/p&gt;

&lt;p&gt;What happened to me?&lt;/p&gt;

&lt;p&gt;So I was creating a simple express server. Things were fine until I got this big error message.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
pnpm dev

&amp;gt; @ dev D:\My Code\Projects\web-dev\full-stack\LEARNING\mycom\backend
&amp;gt; cross-env NODE_ENV=DEV tsx watch src/index.ts

D:\My Code\Projects\web-dev\full-stack\LEARNING\mycom\backend\node_modules\.pnpm\express@5.1.0\node_modules\express\lib\application.js:161
    res.setHeader('X-Powered-By', 'Express');
        ^

TypeError: Cannot read properties of undefined (reading 'setHeader')
    at Function.handle (D:\My Code\Projects\web-dev\full-stack\LEARNING\mycom\backend\node_modules\.pnpm\express@5.1.0\node_modules\express\lib\application.js:161:9)
    at app (D:\My Code\Projects\web-dev\full-stack\LEARNING\mycom\backend\node_modules\.pnpm\express@5.1.0\node_modules\express\lib\express.js:38:9)
    at express (D:\My Code\Projects\web-dev\full-stack\LEARNING\mycom\backend\src\app.ts:34:21)       
    at Object.&amp;lt;anonymous&amp;gt; (D:\My Code\Projects\web-dev\full-stack\LEARNING\mycom\backend\src\app.ts:41:16)
    at Module._compile (node:internal/modules/cjs/loader:1358:14)
    at Object.transformer (D:\My Code\Projects\web-dev\full-stack\LEARNING\mycom\backend\node_modules\.pnpm\tsx@4.20.6\node_modules\tsx\dist\register-D46fvsV_.cjs:3:1104)
    at Module.load (node:internal/modules/cjs/loader:1208:32)
    at Module._load (node:internal/modules/cjs/loader:1024:12)
    at Module.require (node:internal/modules/cjs/loader:1233:19)
    at require (node:internal/modules/helpers:179:18)

Node.js v20.15.1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;I was confused I tried to rerun&lt;/p&gt;

&lt;p&gt;tsconfig.json&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"compilerOptions"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"target"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"es2016"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"module"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"commonjs"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"lib"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"es6"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"dom"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"outDir"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"./dist"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"rootDir"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"./src"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"strict"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"esModuleInterop"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"skipLibCheck"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"forceConsistentCasingInFileNames"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"typeRoots"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"./node_modules/@types"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;//&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;Include&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;default&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;@types&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"./src/types"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;//&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;Path&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;to&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;your&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;custom&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;types&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;directory&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"include"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"src/**/*.ts"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"src/types/**/*.d.ts"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"exclude"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"node_modules"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"**/*.spec.ts"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;backend\src\types\express.d.ts&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;User&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;../generated/prisma&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;


&lt;span class="kr"&gt;declare&lt;/span&gt; &lt;span class="nb"&gt;global&lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="k"&gt;namespace&lt;/span&gt; &lt;span class="nx"&gt;Express&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="kr"&gt;interface&lt;/span&gt; &lt;span class="nx"&gt;Request&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;?:&lt;/span&gt; &lt;span class="nx"&gt;User&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
pnpm dev

&amp;gt; @ dev D:\My Code\Projects\web-dev\full-stack\LEARNING\mycom\backend
&amp;gt; cross-env NODE_ENV=DEV nodemon src/index.ts

[nodemon] 3.1.9
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: ts,json
[nodemon] starting `ts-node src/index.ts`
D:\My Code\Projects\web-dev\full-stack\LEARNING\mycom\backend\node_modules\.pnpm\ts-node@10.9.2_@types+node@24.7.2_typescript@5.9.3\node_modules\ts-node\src\index.ts:859
    return new TSError(diagnosticText, diagnosticCodes, diagnostics);
           ^
TSError: ⨯ Unable to compile TypeScript:
src/middlewares/auth.middleware.ts:33:9 - error TS2339: Property 'user' does not exist on type 'Request&amp;lt;ParamsDictionary, any, any, ParsedQs, Record&amp;lt;string, any&amp;gt;&amp;gt;'.

33     req.user = user;
           ~~~~
src/middlewares/auth.middleware.ts:47:14 - error TS2339: Property 'user' does not exist on type 'Request&amp;lt;ParamsDictionary, any, any, ParsedQs, Record&amp;lt;string, any&amp;gt;&amp;gt;'.

47     if (!req.user) {
                ~~~~
src/middlewares/auth.middleware.ts:51:36 - error TS2339: Property 'user' does not exist on type 'Request&amp;lt;ParamsDictionary, any, any, ParsedQs, Record&amp;lt;string, any&amp;gt;&amp;gt;'.

51     if ( requiredRole.includes(req.user.role) === false ) {
                                      ~~~~

    at createTSError (D:\My Code\Projects\web-dev\full-stack\LEARNING\mycom\backend\node_modules\.pnpm\ts-node@10.9.2_@types+node@24.7.2_typescript@5.9.3\node_modules\ts-node\src\index.ts:859:12)
    at reportTSError (D:\My Code\Projects\web-dev\full-stack\LEARNING\mycom\backend\node_modules\.pnpm\ts-node@10.9.2_@types+node@24.7.2_typescript@5.9.3\node_modules\ts-node\src\index.ts:863:19)
    at getOutput (D:\My Code\Projects\web-dev\full-stack\LEARNING\mycom\backend\node_modules\.pnpm\ts-node@10.9.2_@types+node@24.7.2_typescript@5.9.3\node_modules\ts-node\src\index.ts:1077:36)
    at Object.compile (D:\My Code\Projects\web-dev\full-stack\LEARNING\mycom\backend\node_modules\.pnpm\ts-node@10.9.2_@types+node@24.7.2_typescript@5.9.3\node_modules\ts-node\src\index.ts:1433:41)
    at Module.m._compile (D:\My Code\Projects\web-dev\full-stack\LEARNING\mycom\backend\node_modules\.pnpm\ts-node@10.9.2_@types+node@24.7.2_typescript@5.9.3\node_modules\ts-node\src\index.ts:1617:30)
    at Module._extensions..js (node:internal/modules/cjs/loader:1416:10)
    at Object.require.extensions.&amp;lt;computed&amp;gt; [as .ts] (D:\My Code\Projects\web-dev\full-stack\LEARNING\mycom\backend\node_modules\.pnpm\ts-node@10.9.2_@types+node@24.7.2_typescript@5.9.3\node_modules\ts-node\src\index.ts:1621:12)
    at Module.load (node:internal/modules/cjs/loader:1208:32)
    at Function.Module._load (node:internal/modules/cjs/loader:1024:12)
    at Module.require (node:internal/modules/cjs/loader:1233:19) {
  diagnosticCodes: [ 2339, 2339, 2339 ]
}
[nodemon] app crashed - waiting for file changes before starting...

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;Finally after the hit and trials I got it working.&lt;/p&gt;

&lt;p&gt;package.json&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="err"&gt;scripts:&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="nl"&gt;"dev"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"cross-env NODE_ENV=DEV nodemon --watch 'src/**/*.ts' --exec 'ts-node --files' src/index.ts"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="nl"&gt;"build"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"tsc"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="nl"&gt;"start"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"cross-env NODE_ENV=PROD node dist/index.js"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;tsconfig.json&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"compilerOptions"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"target"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"es2016"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"module"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"commonjs"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"lib"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"es6"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"dom"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"outDir"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"./dist"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"rootDir"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"./src"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"strict"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"esModuleInterop"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"skipLibCheck"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"forceConsistentCasingInFileNames"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"typeRoots"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="s2"&gt;"./node_modules/@types"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;//&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;Include&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;default&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;@types&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="s2"&gt;"./src/types"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;//&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;Path&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;to&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;your&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;custom&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;types&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;directory&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;  
  &lt;/span&gt;&lt;span class="nl"&gt;"include"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"src/**/*.ts"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"src/types/**/*.d.ts"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"exclude"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"node_modules"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"**/*.spec.ts"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;backend\src\types\express\index.d.ts&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;User&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;../../../generated/prisma&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kr"&gt;declare&lt;/span&gt; &lt;span class="kr"&gt;module&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;express&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kr"&gt;interface&lt;/span&gt; &lt;span class="nx"&gt;Request&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; 
    &lt;span class="nl"&gt;user&lt;/span&gt;&lt;span class="p"&gt;?:&lt;/span&gt; &lt;span class="nx"&gt;User&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now let me explain the &lt;code&gt;dev&lt;/code&gt; script&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Development Script:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Always use a dev script like:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;"dev": "nodemon --watch 'src/**/*.ts' --exec 'ts-node --files' src/index.ts"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;--files&lt;/code&gt; flag is crucial to load type augmentation files automatically.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;When you see TS errors like “Property ‘user’ does not exist on type ‘Request’”:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Double-check module augmentation syntax.&lt;/li&gt;
&lt;li&gt;Make sure your dev script includes &lt;code&gt;--files&lt;/code&gt; for ts-node.&lt;/li&gt;
&lt;li&gt;Restart your TypeScript server/IDE after changing types or config.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

</description>
      <category>typescript</category>
      <category>express</category>
      <category>node</category>
      <category>programming</category>
    </item>
    <item>
      <title>uri mismatch issue oauth2 | google | Error 400: redirect_uri_mismatch</title>
      <dc:creator>Atul Anand Oraon</dc:creator>
      <pubDate>Sun, 06 Apr 2025 20:23:11 +0000</pubDate>
      <link>https://dev.to/oatula/uri-mismatch-issue-oauth2-google-error-400-redirecturimismatch-1dgg</link>
      <guid>https://dev.to/oatula/uri-mismatch-issue-oauth2-google-error-400-redirecturimismatch-1dgg</guid>
      <description>&lt;h2&gt;
  
  
  How I Solved My Google OAuth2 Redirect URI Error That Was Hiding in Plain Sight 😒
&lt;/h2&gt;

&lt;p&gt;So I happened to use OAuth2 by Google, but I was getting this error &lt;strong&gt;despite having the exact correct path&lt;/strong&gt;—I copied it straight from my browser’s search bar.&lt;/p&gt;

&lt;p&gt;But to my surprise, I was &lt;strong&gt;still&lt;/strong&gt; getting the error. I was utterly confused. 😵‍💫&lt;/p&gt;




&lt;h2&gt;
  
  
  So this is what I tried:
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Checked the &lt;strong&gt;Network tab&lt;/strong&gt; to see if anything was wrong. It looked good.
&lt;/li&gt;
&lt;li&gt;Copied the &lt;strong&gt;exact address&lt;/strong&gt; from the search bar into the &lt;strong&gt;origin&lt;/strong&gt; and &lt;strong&gt;callback&lt;/strong&gt; fields.
&lt;/li&gt;
&lt;li&gt;What actually worked: I clicked on &lt;code&gt;error detail&lt;/code&gt; 🤯&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdmrav66tt191qb14xas6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdmrav66tt191qb14xas6.png" alt="error detail image" width="800" height="397"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Then came the twist...
&lt;/h2&gt;

&lt;p&gt;I knew I had to check the error details here too. So I clicked it, and to my surprise:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffy4zkuul68s6mf77a7p2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffy4zkuul68s6mf77a7p2.png" alt="Error message" width="800" height="419"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, this was &lt;strong&gt;shocking&lt;/strong&gt;. I saw the &lt;strong&gt;lock icon&lt;/strong&gt; up there while copying, so I &lt;em&gt;assumed&lt;/em&gt; it was &lt;code&gt;https&lt;/code&gt;.&lt;br&gt;&lt;br&gt;
But in reality—it was actually &lt;code&gt;http&lt;/code&gt;.  &lt;/p&gt;

&lt;p&gt;This is &lt;strong&gt;evil in plain sight&lt;/strong&gt;, and honestly, this kind of thing shouldn't even happen. 😒&lt;/p&gt;




&lt;h2&gt;
  
  
  The fix that worked:
&lt;/h2&gt;

&lt;p&gt;I added &lt;code&gt;http&lt;/code&gt; (instead of &lt;code&gt;https&lt;/code&gt;) to &lt;strong&gt;both the origin and the redirect URI&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
Boom. Issue resolved.&lt;/p&gt;

&lt;p&gt;So yeah—next time, take a close look at the error message and match everything properly.&lt;br&gt;&lt;br&gt;
Because if &lt;strong&gt;this&lt;/strong&gt; happened in plain sight, &lt;strong&gt;anything&lt;/strong&gt; can.&lt;/p&gt;

&lt;p&gt;I had already tried all other possibilities and finally ended up solving it with this simple change.&lt;/p&gt;




&lt;p&gt;😋 I didn’t include screenshots of the Network tab to avoid overwhelming you, but trust me—I went deep.&lt;br&gt;&lt;br&gt;
Headers, cookies, requests, responses, shared files—you name it.  &lt;/p&gt;

&lt;p&gt;But yeah, sometimes it's best to &lt;strong&gt;try the simple stuff first&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fca99r8tpgsoshlnff38j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fca99r8tpgsoshlnff38j.png" alt="http added to" width="800" height="410"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Moral of the story:
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Don’t trust the lock icon. Trust your logs and error details. 👀&lt;/p&gt;
&lt;/blockquote&gt;




&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw3ky36mshqslyho3yjpd.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw3ky36mshqslyho3yjpd.gif" alt="Oh computer" width="498" height="269"&gt;&lt;/a&gt;&lt;/p&gt;




</description>
      <category>webdev</category>
      <category>oauth</category>
      <category>google</category>
      <category>programming</category>
    </item>
    <item>
      <title>Auto-Delete Files in S3: A Beginner's Guide</title>
      <dc:creator>Atul Anand Oraon</dc:creator>
      <pubDate>Sat, 08 Feb 2025 14:55:31 +0000</pubDate>
      <link>https://dev.to/oatula/auto-delete-files-in-s3-a-beginners-guide-34b4</link>
      <guid>https://dev.to/oatula/auto-delete-files-in-s3-a-beginners-guide-34b4</guid>
      <description>&lt;h2&gt;
  
  
  Auto-Deleting S3 Files: A Lazy Dev's Best Friend 🦥
&lt;/h2&gt;

&lt;p&gt;Hey folks,&lt;/p&gt;

&lt;p&gt;I'm back after a long break! Let's dive straight into something useful. As the title says, you're gonna learn how to automatically delete files from your S3 bucket.&lt;/p&gt;

&lt;p&gt;Now, you might be thinking, "Why not just delete them programmatically?"   That's a valid thought! You &lt;em&gt;could&lt;/em&gt; write a script and use the AWS SDK  (boto3, anyone?). But, hear me out: it's often better to leverage S3's built-in lifecycle rules for auto-deletion. It saves you API calls, reduces the complexity of your code, and lets AWS handle the heavy lifting. Why reinvent the wheel, right?&lt;/p&gt;

&lt;p&gt;So, let's get started. This is so simple, it's almost cheating. 😉&lt;/p&gt;

&lt;h3&gt;
  
  
  Steps to Auto-Delete Your S3 Files
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt; &lt;strong&gt;Search for &lt;code&gt;S3&lt;/code&gt; in the AWS Console&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fty5mxyotxwwmi2rxpdlu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fty5mxyotxwwmi2rxpdlu.png" alt="Search for the s3" width="800" height="425"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Yeah, the good ol' search bar. Type "S3" and hit enter. You know the drill.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; &lt;strong&gt;Select the &lt;code&gt;bucket&lt;/code&gt; you want to use.&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzf7r2i3o72ylnx4vf893.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzf7r2i3o72ylnx4vf893.png" alt="Bucket" width="800" height="425"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Choose the S3 bucket where you want to enable automatic file deletion.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; &lt;strong&gt;Go to the &lt;code&gt;Management&lt;/code&gt; tab&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi2eu05q9mkndnr8wkbkb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi2eu05q9mkndnr8wkbkb.png" alt="Go to management" width="800" height="425"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is where the magic happens.&lt;/p&gt;

&lt;p&gt;Go to management&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; &lt;strong&gt;Create a Lifecycle Rule&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcdgj9hj0lestzpkqb4i8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcdgj9hj0lestzpkqb4i8.png" alt="Create the Lifecycle" width="800" height="425"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click that beautiful "Create lifecycle rule" button.  &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; &lt;strong&gt;Set the scope&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4pxqk5qgzn8exyi57c50.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4pxqk5qgzn8exyi57c50.png" alt="Set the scope" width="800" height="425"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Choose whether you want the rule to apply to all objects in the bucket or only to specific objects based on a prefix (folder) or tags. For most simple cases, "This rule applies to all objects in the bucket" is what you want. Don't forget to check the acknowledgement box.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; &lt;strong&gt;Add the expiration time&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fezt2vpwhx8rx0nif5hhr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fezt2vpwhx8rx0nif5hhr.png" alt="expiration time" width="800" height="425"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is the key part! Select "Expire current versions of objects" and set the number of days (or even hours!) after which you want the files to be automatically deleted.  For example, setting it to &lt;code&gt;3&lt;/code&gt; will delete files older than 3 days.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; &lt;strong&gt;Lifecycle Applied! 🥳&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv6a3gl5h4t8nfoale7bv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv6a3gl5h4t8nfoale7bv.png" alt="Lifecycle Applied" width="800" height="425"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click "Create rule", and you're done!  S3 will now automatically delete files based on your rule.  Keep in mind that it might take a little while for the rule to kick in .&lt;/p&gt;

&lt;h3&gt;
  
  
  When is this useful?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Log file management:&lt;/strong&gt; Automatically delete old log files to save on storage costs.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Temporary files:&lt;/strong&gt;  If you're storing temporary files in S3, set a lifecycle rule to clean them up after a certain period.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Backups:&lt;/strong&gt; Rotate backups by automatically deleting older versions.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Alternatives
&lt;/h3&gt;

&lt;p&gt;While lifecycle rules are generally the easiest way to go, you &lt;em&gt;can&lt;/em&gt; also use the AWS CLI or SDKs to delete files programmatically.  For example, you could use the AWS CLI command &lt;code&gt;aws s3 rm s3://your-bucket-name/path/to/files --recursive&lt;/code&gt; in a cron job. However, this requires you to manage the scheduling and execution of the script.&lt;/p&gt;

</description>
      <category>aws</category>
      <category>s3</category>
      <category>webdev</category>
      <category>devops</category>
    </item>
    <item>
      <title>Useful and cool Linux tricks</title>
      <dc:creator>Atul Anand Oraon</dc:creator>
      <pubDate>Fri, 13 Sep 2024 16:47:44 +0000</pubDate>
      <link>https://dev.to/oatula/useful-and-cool-linux-tricks-dio</link>
      <guid>https://dev.to/oatula/useful-and-cool-linux-tricks-dio</guid>
      <description>&lt;p&gt;Hi folks &lt;/p&gt;

&lt;p&gt;I recently joined th community fcall on the discord server of the Growin Community. There we had a Linux session in which we learn't quite some handy tricks with the Linux.&lt;/p&gt;

&lt;p&gt;If you do not own a linux machine do not worry. You can use &lt;/p&gt;

&lt;p&gt;1 &lt;a href="https://killercoda.com/playgrounds" rel="noopener noreferrer"&gt;Killer koda&lt;/a&gt;&lt;br&gt;
Just choose the ubuntu from here&lt;br&gt;
2 &lt;a href="https://copy.sh/v86/?profile=linux26&amp;amp;ref=itsfoss.com" rel="noopener noreferrer"&gt;copy.sh&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Alright you are all set to get your hands on the terminal.&lt;br&gt;&lt;br&gt;
3,2, 1 Go 🔫🚀&lt;/p&gt;

&lt;h2&gt;
  
  
  LINUX Tricks
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;To execute a previous command:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;history&lt;/code&gt; — prints the history of commands.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;!&amp;lt;cmd_no&amp;gt;&lt;/code&gt; — executes a command from history based on its number.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;To copy and paste lines in &lt;code&gt;vim&lt;/code&gt;:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;Esc + 10yy&lt;/code&gt; — copies 10 lines.&lt;/li&gt;
&lt;li&gt;Paste with &lt;code&gt;p&lt;/code&gt; to insert after the cursor.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;To perform a reverse search:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;Ctrl+R&lt;/code&gt; — reverse search through the command history.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;To count lines in a file:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;wc -l aks.txt&lt;/code&gt; — counts and lists the number of lines.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Yanking (copying) in &lt;code&gt;vim&lt;/code&gt;:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;yy&lt;/code&gt; — yanks (copies) the current line.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Esc + 5yy&lt;/code&gt; — yanks (copies) 5 lines.&lt;/li&gt;
&lt;li&gt;Paste with &lt;code&gt;p&lt;/code&gt; after yanking.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Navigating in &lt;code&gt;vim&lt;/code&gt;:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;Esc + :1&lt;/code&gt; — jumps to line 1.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;:set nu&lt;/code&gt; — enables line numbers.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Esc + Shift+G&lt;/code&gt; — moves to the end of the document.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Deleting in &lt;code&gt;vim&lt;/code&gt;:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;Esc + dG&lt;/code&gt; — deletes everything from the current line to the end of the document.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Esc + u&lt;/code&gt; — undoes the last change.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Finding unique adjacent lines in a file:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;uniq -c&lt;/code&gt; — looks for unique adjacent lines.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Sorting, unique filtering, and counting occurrences:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;cat aks.txt | sort | uniq -c&lt;/code&gt; — lists all unique lines in &lt;code&gt;aks.txt&lt;/code&gt; with their counts after sorting. &lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;That's it you got a lot from this article do like it and share any comments &lt;br&gt;
you want to. DO not shy away.&lt;/p&gt;

&lt;p&gt;See you next time&lt;/p&gt;

</description>
      <category>linux</category>
      <category>vim</category>
      <category>terminal</category>
    </item>
    <item>
      <title>Useful and cool Linux and Vim tricks</title>
      <dc:creator>Atul Anand Oraon</dc:creator>
      <pubDate>Tue, 10 Sep 2024 17:15:23 +0000</pubDate>
      <link>https://dev.to/oatula/useful-and-cool-linux-and-vim-tricks-bfi</link>
      <guid>https://dev.to/oatula/useful-and-cool-linux-and-vim-tricks-bfi</guid>
      <description>&lt;p&gt;Hi folks,&lt;/p&gt;

&lt;p&gt;I recently joined the community call on the Discord server of the &lt;a href="https://www.linkedin.com/company/growincommunity" rel="noopener noreferrer"&gt;Growin Community&lt;/a&gt;. We had a Linux session where we learned some handy tricks with Linux.&lt;/p&gt;

&lt;p&gt;If you don’t own a Linux machine, don’t worry! You can use:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;a href="https://killercoda.com/playgrounds" rel="noopener noreferrer"&gt;Killer Koda&lt;/a&gt; — Just choose Ubuntu from here.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://copy.sh/v86/?profile=linux26&amp;amp;ref=itsfoss.com" rel="noopener noreferrer"&gt;copy.sh&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Alright, you're all set to get your hands on the terminal.&lt;br&gt;&lt;br&gt;
3, 2, 1, Go! 🔫🚀&lt;/p&gt;

&lt;h2&gt;
  
  
  LINUX Tricks
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;To execute a previous command:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;history&lt;/code&gt; — prints the history of commands.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;!&amp;lt;cmd_no&amp;gt;&lt;/code&gt; — executes a command from history based on its number.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;To copy and paste lines in &lt;code&gt;vim&lt;/code&gt;:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;Esc + 10yy&lt;/code&gt; — copies 10 lines.&lt;/li&gt;
&lt;li&gt;Paste with &lt;code&gt;p&lt;/code&gt; to insert after the cursor.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;To perform a reverse search:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;Ctrl+R&lt;/code&gt; — reverse search through the command history.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;To count lines in a file:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;wc -l aks.txt&lt;/code&gt; — counts and lists the number of lines.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Yanking (copying) in &lt;code&gt;vim&lt;/code&gt;:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;yy&lt;/code&gt; — yanks (copies) the current line.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Esc + 5yy&lt;/code&gt; — yanks (copies) 5 lines.&lt;/li&gt;
&lt;li&gt;Paste with &lt;code&gt;p&lt;/code&gt; after yanking.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Navigating in &lt;code&gt;vim&lt;/code&gt;:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;Esc + :1&lt;/code&gt; — jumps to line 1.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;:set nu&lt;/code&gt; — enables line numbers.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Esc + Shift+G&lt;/code&gt; — moves to the end of the document.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Deleting in &lt;code&gt;vim&lt;/code&gt;:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;Esc + dG&lt;/code&gt; — deletes everything from the current line to the end of the document.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Esc + u&lt;/code&gt; — undoes the last change.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Finding unique adjacent lines in a file:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;uniq -c&lt;/code&gt; — looks for unique adjacent lines.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Sorting, unique filtering, and counting occurrences:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;cat aks.txt | sort | uniq -c&lt;/code&gt; — lists all unique lines in &lt;code&gt;aks.txt&lt;/code&gt; with their counts after sorting. &lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;That's it! You’ve learned a lot from this article. Do like it and share any comments you have. Don’t shy away!&lt;/p&gt;

&lt;p&gt;See you next time!&lt;/p&gt;

</description>
      <category>linux</category>
      <category>vim</category>
      <category>terminal</category>
    </item>
    <item>
      <title>React Rendering the component Twice</title>
      <dc:creator>Atul Anand Oraon</dc:creator>
      <pubDate>Wed, 22 May 2024 21:45:13 +0000</pubDate>
      <link>https://dev.to/oatula/react-rendering-the-component-twice-5c5n</link>
      <guid>https://dev.to/oatula/react-rendering-the-component-twice-5c5n</guid>
      <description>&lt;p&gt;Hi Techies&lt;/p&gt;

&lt;p&gt;If you are using React, you would definitely be using the &lt;code&gt;useEffect&lt;/code&gt; hook right?&lt;/p&gt;

&lt;p&gt;What if I told you that the React Renders twice and it's a simple bug 🤨️?&lt;br&gt;
Yeah that's right it's a very small bug, but yet underlooked, although it's only on our local system and not on the actual production build.&lt;br&gt;
But wait a minute, even if it is just in the dev mode. we use &lt;code&gt;vite&lt;/code&gt; or other&lt;br&gt;&lt;br&gt;
tools to keep the app running and reflect the changes live. Also, most of us have turned on the &lt;em&gt;auto-save&lt;/em&gt; option as the cherry on top.&lt;/p&gt;

&lt;p&gt;This becomes a hectic challenge when we use &lt;code&gt;useEffect&lt;/code&gt; to make the &lt;br&gt;
API calls. As some free APIs have a limit of 100 calls a day, so I would recommend turning off the auto-save on your IDE to stay safe.&lt;/p&gt;

&lt;p&gt;Now After this small story, what would be a feasible solution you may ask?&lt;br&gt;
I have a very simple yet effective solution for Ya. So great if you are following along. Let's see how to tackle this bully.&lt;/p&gt;

&lt;p&gt;First of we would like to have some environment variables. Yeah, this would be beneficial,  you could choose to name it &lt;code&gt;environment&lt;/code&gt; or &lt;code&gt;mode&lt;/code&gt;. Here let's go with the &lt;code&gt;environment&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;In your .env.local you can have it like&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;VITE_Environent="DEV"
# if using vite
REACT_APP_Environent="DEV"
# If using create-react-app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Have a file to store your environment variables like this&lt;/p&gt;

&lt;p&gt;env.config.ts&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;RAPIDAPI_KEY&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;meta&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;VITE_RAPIDAPI_KEY&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;RAPIDAPI_HOST&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;meta&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;VITE_RapidAPI_Host&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;ENVIRONMENT&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;meta&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;VITE_Environent&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;ENVS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
 &lt;span class="na"&gt;RAPIDAPI_KEY&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;RAPIDAPI_KEY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
 &lt;span class="na"&gt;RAPIDAPI_HOST&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;RAPIDAPI_HOST&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
 &lt;span class="na"&gt;ENVIRONMENT&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;ENVIRONMENT&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;ENVS&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I am exporting it like so, to avoid the typos as only by console logs you can detect them so better to do it here once and import and use them elsewhere. Also, look at the naming convention and replace the  &lt;code&gt;VITE_&lt;/code&gt; with &lt;code&gt;REACT_APP_&lt;/code&gt; for a smooth experience.&lt;/p&gt;

&lt;p&gt;Now, here comes the juicy part for which you have been reading this blog &lt;br&gt;
the proper way to do it.&lt;/p&gt;

&lt;p&gt;main.tsx&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;memo&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;ReactDOM&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react-dom/client&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Route&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;BrowserRouter&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nx"&gt;Router&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Routes&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react-router-dom&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./App.tsx&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./index.css&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Provider&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react-redux&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;store&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./state/store.ts&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;ProductsPage&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./pages/ProductsPage.tsx&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;NotFound&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./pages/NotFound.tsx&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;ENVS&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./env.config.ts&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;renderApp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
 &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Provider&lt;/span&gt; &lt;span class="na"&gt;store&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;store&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
 &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Router&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
 &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Routes&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
 &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Route&lt;/span&gt; &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/"&lt;/span&gt; &lt;span class="na"&gt;element&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;App&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
 &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Route&lt;/span&gt; &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"products"&lt;/span&gt; &lt;span class="na"&gt;element&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;ProductsPage&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
 &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Route&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
 &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Route&lt;/span&gt; &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"*"&lt;/span&gt; &lt;span class="na"&gt;element&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;NotFound&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
 &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Routes&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
 &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Router&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
 &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Provider&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;ENVS.ENVIRONMENT&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;ENVS&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;ENVIRONMENT&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;// Conditionally wrap in React.StrictMode based on the environment&lt;/span&gt;
&lt;span class="c1"&gt;// As it is the one causing this issue&lt;/span&gt;
&lt;span class="c1"&gt;// React.StrictMode &lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
 &lt;span class="nx"&gt;ENVS&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;ENVIRONMENT&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;DEV&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
 &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;StrictMode&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nf"&gt;renderApp&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;StrictMode&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
 &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
 &lt;span class="nf"&gt;renderApp&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
 &lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;ReactDOM&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createRoot&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;root&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here we have just a simple little change. &lt;br&gt;
We made an arrow function &lt;code&gt;renderApp&lt;/code&gt; which is a simple &lt;code&gt;JSX.element&lt;/code&gt;&lt;br&gt;
and conditionally put it inside the &lt;code&gt;&amp;lt;React.StrictMode&amp;gt;&lt;/code&gt; if the the Environment is not &lt;code&gt;DEV&lt;/code&gt; . It does the job and we get the best of both worlds. &lt;/p&gt;

&lt;p&gt;Also if you feel at any moment you need the &lt;code&gt;React.StrictMode&lt;/code&gt; ,  you can &lt;br&gt;
easily do so by just putting the &lt;code&gt;renderApp()&lt;/code&gt; in the &lt;code&gt;React.StrictMode&lt;/code&gt; .&lt;/p&gt;

&lt;p&gt;I know this is going to surely help. Keep coding.&lt;/p&gt;

</description>
      <category>react</category>
      <category>bug</category>
      <category>feature</category>
    </item>
    <item>
      <title>How to cleanup Linux | Ubuntu</title>
      <dc:creator>Atul Anand Oraon</dc:creator>
      <pubDate>Sun, 05 May 2024 11:00:19 +0000</pubDate>
      <link>https://dev.to/oatula/how-to-cleanup-linux-ubuntu-57b3</link>
      <guid>https://dev.to/oatula/how-to-cleanup-linux-ubuntu-57b3</guid>
      <description>&lt;p&gt;Well, I recently got alerts on my local system getting full. But wait a minute.&lt;br&gt;
I do not have a lot on my system. I got sus about it.&lt;br&gt;
Just the usual thing which will come to my mind is to check, if, my Downloads dir got too big. Sheesh, not it isn't weighing just 16.5GB light.&lt;br&gt;
Well, that's nothing.&lt;/p&gt;

&lt;p&gt;I then went on to look at the rest of my folder structure. Nothing was to be found. Well, then I thought let's get on the journey to the West ;)&lt;/p&gt;

&lt;p&gt;Sometimes we get to a point where despite very less or no usage&lt;br&gt;&lt;br&gt;
our Linux seems to get full. As if it got fed some nice extra large pizza with some extra cheese and chili flakes.&lt;/p&gt;

&lt;p&gt;It is kind of funny, I had to look a lot for it.&lt;/p&gt;

&lt;p&gt;With a lot of trial and error, I accumulated these ways.&lt;/p&gt;

&lt;p&gt;Well, this tutorial also taught me a lot.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://youtu.be/o-WPKXaiL7s?si=WJkiWsDHSFF9xGWL" rel="noopener noreferrer"&gt;Youtube Tutorial&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;First off let's get a bit commanding.&lt;br&gt;
Ahem, just paste this into your terminal to see the disk usage&lt;/p&gt;

&lt;p&gt;For the HDD use this&lt;br&gt;
&lt;code&gt;df -TH | grep "/dev/sda"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;For the nvme/ssd use this&lt;br&gt;
&lt;code&gt;df -TH | grep "/dev/nvme*"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The output would be like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;
/dev/nvme0n1p6 ext4      194G  120G   65G  66% /
/dev/nvme0n1p5 ext4      990M  507M  415M  56% /boot
/dev/nvme0n1p1 vfat      269M   73M  197M  27% /boot/efi
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Let's now remove any unwanted dependencies
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt-get autoremove &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;sudo &lt;/span&gt;apt-get autoclean
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The auto clean will remove any broken library files.&lt;/p&gt;

&lt;h2&gt;
  
  
  Further remove the unwanted configs of removed dependencies
&lt;/h2&gt;

&lt;p&gt;This command will purge any packages that were previously removed but left configuration files behind.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt purge &lt;span class="si"&gt;$(&lt;/span&gt;dpkg &lt;span class="nt"&gt;-l&lt;/span&gt; | &lt;span class="nb"&gt;awk&lt;/span&gt; &lt;span class="s1"&gt;'/^rc/ {print $2}'&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here's how it works:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    dpkg -l lists all installed packages
    awk '/^rc/ {print $2}' filters the output to only include 
packages with an 'rc' status (removed with config files left behind) 
and prints the second field (package name)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Let's clear some cache
&lt;/h2&gt;

&lt;p&gt;So in the Linux, our cache can be in two places&lt;/p&gt;

&lt;p&gt;/var/cache&lt;br&gt;
~/.cache&lt;br&gt;
To clean them simply do this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;~ via  v20.10.0 
┌───────────────────
│
└─&amp;gt; &lt;span class="nb"&gt;du&lt;/span&gt; &lt;span class="nt"&gt;-sh&lt;/span&gt; .cache/
153M    .cache/

~ via  v20.10.0 
┌───────────────────
│
└─&amp;gt; &lt;span class="nb"&gt;cd&lt;/span&gt; .cache/

~/.cache 
┌───────────────────
│
└─&amp;gt; &lt;span class="nb"&gt;sudo &lt;/span&gt;apt clean

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This way you can clean your cache dir same goes for the /var/cache&lt;/p&gt;

&lt;h2&gt;
  
  
  System level files
&lt;/h2&gt;

&lt;p&gt;As we know, &lt;strong&gt;systemd&lt;/strong&gt; oversees both kernel and user-level processes, serving as the &lt;strong&gt;init&lt;/strong&gt; process launched by the kernel during boot. Following this, &lt;strong&gt;systemctl&lt;/strong&gt; orchestrates the startup of systemd and other crucial processes, first at the system level and then at the user level.&lt;br&gt;
&lt;strong&gt;journald&lt;/strong&gt; is one such process which handles the logging.&lt;/p&gt;

&lt;p&gt;We can use &lt;strong&gt;journalctl&lt;/strong&gt; to handle the logs.&lt;/p&gt;

&lt;p&gt;Let's just simply type &lt;code&gt;sudo journalctl&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Smack it, You will se something like this in the output.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;May 05 02:42:20 idea systemd-journald[447]: System Journal &lt;span class="o"&gt;(&lt;/span&gt;/var/log/journal/13&amp;gt;
May 05 02:42:20 idea &lt;span class="nb"&gt;sudo&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;98578]: pam_unix&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;sudo&lt;/span&gt;:session&lt;span class="o"&gt;)&lt;/span&gt;: session closed &lt;span class="k"&gt;for &lt;/span&gt;us&amp;gt;
May 05 02:42:21 idea python[98637]: /usr/local/bin/cpufreqctl.auto-cpufreq: lin&amp;gt;
May 05 02:42:21 idea python[98637]: /usr/local/bin/cpufreqctl.auto-cpufreq: lin&amp;gt;
May 05 02:42:21 idea python[98637]: /usr/local/bin/cpufreqctl.auto-cpufreq: lin&amp;gt;
May 05 02:42:21 idea python[98637]: /usr/local/bin/cpufreqctl.auto-cpufreq: lin&amp;gt;
May 05 02:42:21 idea python[98637]: /usr/local/bin/cpufreqctl.auto-cpufreq: lin&amp;gt;
May 05 02:42:21 idea python[98637]: /usr/local/bin/cpufreqctl.auto-cpufreq: lin&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;BTW, to exit this log press q, or,  you may prefer to watch all of it by pressing down arrow or scrolling.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Now let's make things simpler and see the previous boot logs.&lt;br&gt;
Below is the command for that.&lt;br&gt;
&lt;code&gt;sudo journalctl -b&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;It will show you the similar log again.&lt;/p&gt;

&lt;p&gt;Now lets list all the journals &lt;/p&gt;

&lt;p&gt;&lt;code&gt;journalctl --list-boots&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;And you would have something like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;-2 af75e0d9a21a45f28653826f41945f0e Sun 2024-05-05 02:42:20 IST—Sun 2024-05-05 &amp;gt;
-1 a68bb606747340c298469ca6d9c0a1d6 Sun 2024-05-05 13:29:28 IST—Sun 2024-05-05 &amp;gt;
 0 27d70b75e7624865bb37107c7d054b0c Sun 2024-05-05 14:48:15 IST—Sun 2024-05-05 &amp;gt;
lines 1-3/3 (END)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You might find 8 to 10 entries too.&lt;/p&gt;

&lt;p&gt;Now you can watch for the specific date, logs by simply wirting its index as displayed.&lt;/p&gt;

&lt;p&gt;say &lt;code&gt;sudo journalctl -b -2&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You will have a nice list of logs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;May 05 02:42:20 idea systemd-journald[447]: System Journal &lt;span class="o"&gt;(&lt;/span&gt;/var/log/journal/13&amp;gt;
May 05 02:42:20 idea &lt;span class="nb"&gt;sudo&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;98578]: pam_unix&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;sudo&lt;/span&gt;:session&lt;span class="o"&gt;)&lt;/span&gt;: session closed &lt;span class="k"&gt;for &lt;/span&gt;us&amp;gt;
May 05 02:42:21 idea python[98637]: /usr/local/bin/cpufreqctl.auto-cpufreq: lin&amp;gt;
May 05 02:42:21 idea python[98637]: /usr/local/bin/cpufreqctl.auto-cpufreq: lin&amp;gt;
May 05 02:42:21 idea python[98637]: /usr/local/bin/cpufreqctl.auto-cpufreq: lin&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also watch since a particular duration say 4 hours.&lt;/p&gt;

&lt;p&gt;Just type ahead &lt;code&gt;sudo journalctl --since "4 hours ago"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Yet again you will have a lovely logs&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;May 05 13:29:28 idea kernel: Linux version 6.5.0-060500-generic &lt;span class="o"&gt;(&lt;/span&gt;kernel@kathleen&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;x86_64-linux-gnu-gcc-13 &lt;span class="o"&gt;(&lt;/span&gt;Ubuntu &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
May 05 13:29:28 idea kernel: Command line: &lt;span class="nv"&gt;BOOT_IMAGE&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/vmlinuz-6.5.0-060500-generic &lt;span class="nv"&gt;root&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;UUID&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;08169e91-a06a-4efc-b9&amp;gt;
May 05 13:29:28 idea kernel: KERNEL supported cpus:
May 05 13:29:28 idea kernel:   Intel GenuineIntel
May 05 13:29:28 idea kernel:   AMD AuthenticAMD
May 05 13:29:28 idea kernel:   Hygon HygonGenuine
May 05 13:29:28 idea kernel:   Centaur CentaurHauls
May 05 13:29:28 idea kernel:   zhaoxin   Shanghai  
May 05 13:29:28 idea kernel: BIOS-provided physical RAM map:
May 05 13:29:28 idea kernel: BIOS-e820: &lt;span class="o"&gt;[&lt;/span&gt;mem 0x0000000000000000-0x000000000009efff] usable
May 05 13:29:28 idea kernel: BIOS-e820: &lt;span class="o"&gt;[&lt;/span&gt;mem 0x000000000009f000-0x00000000000bffff] reserved
May 05 13:29:28 idea kernel: BIOS-e820: &lt;span class="o"&gt;[&lt;/span&gt;mem 0x0000000000100000-0x0000000009afffff] usable
May 05 13:29:28 idea kernel: BIOS-e820: &lt;span class="o"&gt;[&lt;/span&gt;mem 0x0000000009b00000-0x0000000009dfffff] reserved
May 05 13:29:28 idea kernel: BIOS-e820: &lt;span class="o"&gt;[&lt;/span&gt;mem 0x0000000009e00000-0x0000000009efffff] usable
May 05 13:29:28 idea kernel: BIOS-e820: &lt;span class="o"&gt;[&lt;/span&gt;mem 0x0000000009f00000-0x0000000009f11fff] ACPI NVS
May 05 13:29:28 idea kernel: BIOS-e820: &lt;span class="o"&gt;[&lt;/span&gt;mem 0x0000000009f12000-0x000000009fffefff] usable
May 05 13:29:28 idea kernel: BIOS-e820: &lt;span class="o"&gt;[&lt;/span&gt;mem 0x000000009ffff000-0x000000009fffffff] reserved
May 05 13:29:28 idea kernel: BIOS-e820: &lt;span class="o"&gt;[&lt;/span&gt;mem 0x00000000a0000000-0x00000000a2363fff] usable
May 05 13:29:28 idea kernel: BIOS-e820: &lt;span class="o"&gt;[&lt;/span&gt;mem 0x00000000a2364000-0x00000000a4563fff] reserved
May 05 13:29:28 idea kernel: BIOS-e820: &lt;span class="o"&gt;[&lt;/span&gt;mem 0x00000000a4564000-0x00000000a456cfff] usable
Ma
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you might want to know how much disk usage does it takes.&lt;br&gt;
Here's the command to know that.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sudo journalctl --disk-usage&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Output will be like&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;Archived and active journals take up 48.0M &lt;span class="k"&gt;in &lt;/span&gt;the file system.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now to mark the active journal logs as archived we need to rotate it, kind of like, closing the notebook.&lt;br&gt;
Here's the command&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sudo journalctl --rotate&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Well this might be a bit confusing. Let me simplify it for you.&lt;br&gt;
You can think of it as the journalctl is journaling. You went ahead&lt;br&gt;
and told it to stop using this page and start writing the rest of the stuff&lt;br&gt;
on the new page. That's what it is at core.&lt;/p&gt;
&lt;h3&gt;
  
  
  Taking the backup
&lt;/h3&gt;

&lt;p&gt;Now for some reason you decide to take the backup of the logs.&lt;br&gt;
As we know, the logs are really precious.&lt;/p&gt;

&lt;p&gt;You can do it simply like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo cp&lt;/span&gt; &lt;span class="nt"&gt;-r&lt;/span&gt; /var/log/journal/&lt;span class="k"&gt;*&lt;/span&gt; /path/to/backup/directory/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or if you want to zip it&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo tar &lt;/span&gt;czvf journal_backup.tar.gz /var/log/journal/&lt;span class="k"&gt;*&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now what if, you want to backup last 5 logs. &lt;br&gt;
I got you &lt;/p&gt;

&lt;p&gt;here is the command for it&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo cp&lt;/span&gt; &lt;span class="nt"&gt;-r&lt;/span&gt; &lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-lt&lt;/span&gt; /var/log/journal/ | &lt;span class="nb"&gt;grep &lt;/span&gt;systemd-journal | &lt;span class="nb"&gt;awk&lt;/span&gt; &lt;span class="s1"&gt;'{print $NF}'&lt;/span&gt; | &lt;span class="nb"&gt;head&lt;/span&gt; &lt;span class="nt"&gt;-n&lt;/span&gt; 5&lt;span class="si"&gt;)&lt;/span&gt; /path/to/backup/directory/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here is the tar way&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo tar &lt;/span&gt;czvf journal_backup.tar.gz &lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-lt&lt;/span&gt; /var/log/journal/ | &lt;span class="nb"&gt;grep &lt;/span&gt;systemd-journal | &lt;span class="nb"&gt;awk&lt;/span&gt; &lt;span class="s1"&gt;'{print $NF}'&lt;/span&gt; | &lt;span class="nb"&gt;head&lt;/span&gt; &lt;span class="nt"&gt;-n&lt;/span&gt; 5&lt;span class="si"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;awk '{print $NF}'&lt;/code&gt; part extracts the file or directory names from the output.&lt;/p&gt;

&lt;h2&gt;
  
  
  Deleting the journals
&lt;/h2&gt;

&lt;p&gt;Now we have to delete a few journals.  Consdier it like vacuum  cleaning stuff.&lt;br&gt;
Let's delete everything older than yesterday(the previous day)&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sudo journalctl --vacuum-time 1d&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This is my output since I already cleaned yesterday.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;Vacuuming &lt;span class="k"&gt;done&lt;/span&gt;, freed 0B of archived journals from /run/log/journal.
Vacuuming &lt;span class="k"&gt;done&lt;/span&gt;, freed 0B of archived journals from /var/log/journal/13da9b9ba4b64ddebab4fcc2387bfa6d.
Vacuuming &lt;span class="k"&gt;done&lt;/span&gt;, freed 0B of archived journals from /var/log/journal.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next you can again check your journalctl disk usage.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;journalctl &lt;span class="nt"&gt;--disk-usage&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;Archived and active journals take up 64.0M &lt;span class="k"&gt;in &lt;/span&gt;the file system.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Cleaning the thumbnails in the cache
&lt;/h2&gt;

&lt;p&gt;You might do it if you like it.&lt;br&gt;
Here's the command for that.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sudo rm -rf ~/.cache/thumbnails/*&lt;/code&gt;    &lt;/p&gt;
&lt;h2&gt;
  
  
  Removing the old revisions of snaps
&lt;/h2&gt;

&lt;p&gt;For my snappy friends I got you too.&lt;br&gt;
You should  put the below in a shell file and then run or &lt;br&gt;
if you decide to directly paste it don't copy the &lt;code&gt;set -eu&lt;/code&gt; part&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;
&lt;span class="c"&gt;# Set DISPLAY and XAUTHORITY environment variables to run in the &lt;/span&gt;
&lt;span class="c"&gt;# graphical environment without this notify-send does not work on my &lt;/span&gt;
&lt;span class="c"&gt;# machine&lt;/span&gt;

&lt;span class="nv"&gt;DISPLAY&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;:0
&lt;span class="nv"&gt;XAUTHORITY&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;~/.Xauthority

&lt;span class="nb"&gt;set&lt;/span&gt; &lt;span class="nt"&gt;-eu&lt;/span&gt;

&lt;span class="nv"&gt;LANG&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;C snap list &lt;span class="nt"&gt;--all&lt;/span&gt; | &lt;span class="nb"&gt;awk&lt;/span&gt; &lt;span class="s1"&gt;'/disabled/{print $1, $3}'&lt;/span&gt; |
    &lt;span class="k"&gt;while &lt;/span&gt;&lt;span class="nb"&gt;read &lt;/span&gt;snaprename revision&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do 
        &lt;/span&gt;snap remove &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$snapname&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="nt"&gt;--revision&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$revision&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
    &lt;span class="k"&gt;done
&lt;/span&gt;&lt;span class="nv"&gt;DISPLAY&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;:0 notify-send &lt;span class="s2"&gt;"Cleaned the snappy snaps revisions ;)"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's have some details about what it does.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;set -eu: This line sets two options for the shell:&lt;/li&gt;
&lt;li&gt;-e (errexit): Causes the shell to exit immediately, if any command exits with a non-zero status (i.e., an error).&lt;/li&gt;
&lt;li&gt;-u (nounset): Treats unset variables as an error when they are referenced.&lt;/li&gt;
&lt;li&gt;LANG=C : sets the language to English&lt;/li&gt;
&lt;li&gt;awk '/disabled/{print $1, $3}' : looks for lines containing the word "disabled" and prints the 1st and 3rd field&lt;/li&gt;
&lt;li&gt;while read snapname revision; do: This starts a while loop, that reads each line of output from the awk command. It assigns the 1st  field to the variable snapname and the 3rd field to the variable revision.&lt;/li&gt;
&lt;li&gt;snap remove "$snapname" --revision="$revision": This command removes the specified snap package ($snapname) at the specified revision ($revision) using the snap remove command.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>linux</category>
      <category>devops</category>
    </item>
    <item>
      <title>Docker Basics beginner to pro</title>
      <dc:creator>Atul Anand Oraon</dc:creator>
      <pubDate>Wed, 10 Apr 2024 19:41:19 +0000</pubDate>
      <link>https://dev.to/oatula/docker-1c5j</link>
      <guid>https://dev.to/oatula/docker-1c5j</guid>
      <description>&lt;h1&gt;
  
  
  Docker
&lt;/h1&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Use Docker without sudo&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;For this, we need to add the user to the docker mod.&lt;/p&gt;

&lt;p&gt;Below is the terminal command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;usermod &lt;span class="nt"&gt;-a&lt;/span&gt; &lt;span class="nt"&gt;-G&lt;/span&gt; docker userName
&lt;span class="c"&gt;#or&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;usermod &lt;span class="nt"&gt;-a&lt;/span&gt; &lt;span class="nt"&gt;-G&lt;/span&gt; docker &lt;span class="nv"&gt;$USER&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we need to logout and login again to see effects.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pull and run a public docker image from the docker hub.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Here’s the command&lt;/p&gt;

&lt;p&gt;version is optional&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker run image:version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Docker advantages
&lt;/h3&gt;

&lt;p&gt;1 Its light&lt;/p&gt;

&lt;p&gt;2 Its fast &lt;/p&gt;

&lt;p&gt;3 It allows to have different configuration layer&lt;/p&gt;

&lt;p&gt;i.e. We can separate it form the actual OS configs.&lt;/p&gt;

&lt;p&gt;4 We also get the benefit of running the same image &lt;/p&gt;

&lt;p&gt;with different versions simultaneously on the same computer.&lt;/p&gt;

&lt;h2&gt;
  
  
  Basic Commands
&lt;/h2&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;docker pull imageName:version&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;This gets the public image from docker hub.&lt;/p&gt;

&lt;p&gt;The version is optional&lt;/p&gt;

&lt;h3&gt;
  
  
  docker images
&lt;/h3&gt;

&lt;p&gt;It shows the list of all images&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;REPOSITORY               TAG       IMAGE ID       CREATED         SIZE
redis                    latest    e10bd12f0b2d   7 days ago      138MB
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;docker run imageName:version&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Here things get interesting.&lt;/p&gt;

&lt;p&gt;If you mentioned the version while pulling, you must do so now too.&lt;/p&gt;

&lt;p&gt;Else docker will pull the latest version of it and then run it.&lt;/p&gt;

&lt;p&gt;💡 Well, you can stop it by just doing a &lt;code&gt;Ctrl+C&lt;/code&gt; that's it.&lt;/p&gt;

&lt;h3&gt;
  
  
  docker ps
&lt;/h3&gt;

&lt;p&gt;lists down all the currently running images.&lt;/p&gt;

&lt;p&gt;💡 We can also use &lt;code&gt;Ctrl+C&lt;/code&gt; to stop the image&lt;/p&gt;

&lt;h3&gt;
  
  
  docker run -d imageName
&lt;/h3&gt;

&lt;p&gt;To run the image in detached mode i.e. now &lt;code&gt;Ctrl+C&lt;/code&gt; won’t work on it.&lt;/p&gt;

&lt;p&gt;It runs in detached mode&lt;/p&gt;

&lt;p&gt;example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker run &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="nt"&gt;-p3000&lt;/span&gt;:3000 &lt;span class="nt"&gt;--name&lt;/span&gt; node-app example-node
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Now to stop a detached image
&lt;/h3&gt;

&lt;p&gt;We need to &lt;/p&gt;

&lt;p&gt;💡 &lt;code&gt;docker ps&lt;/code&gt;&lt;br&gt;
Now we have the id &lt;br&gt;
We can stop it simply using&lt;br&gt;
&lt;code&gt;docker stop id&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  docker ps -a
&lt;/h3&gt;

&lt;p&gt;This prints the whole history.&lt;/p&gt;

&lt;p&gt;From here we can start a container with its id.&lt;/p&gt;

&lt;p&gt;by using the command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker start &lt;span class="nb"&gt;id&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  docker run -p:containerPort image:version
&lt;/h3&gt;

&lt;p&gt;Now the command above looks a bit big.&lt;/p&gt;

&lt;p&gt;Let me break it down.&lt;/p&gt;

&lt;p&gt;Let’s first have an example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker run &lt;span class="nt"&gt;-p9000&lt;/span&gt;:6379 &lt;span class="nt"&gt;-d&lt;/span&gt; redis
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker ps
CONTAINER ID   IMAGE     COMMAND                  CREATED          STATUS          PORTS                                       NAMES
5aeaf8ee3849   redis     &lt;span class="s2"&gt;"docker-entrypoint.s…"&lt;/span&gt;   14 seconds ago   Up 11 seconds   0.0.0.0:9000-&amp;gt;6379/tcp, :::9000-&amp;gt;6379/tcp   xenodochial_curran
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This helps us bind a host port to the container port.&lt;/p&gt;

&lt;p&gt;This is really helpful when we want to run 2 versions of the same image.&lt;/p&gt;

&lt;p&gt;We can bind them to 2 different ports.&lt;/p&gt;

&lt;h3&gt;
  
  
  docker logs id
&lt;/h3&gt;

&lt;p&gt;This helps us see the logs of a container.&lt;/p&gt;

&lt;p&gt;This helps us solve bugs and errors.&lt;/p&gt;

&lt;p&gt;💡 we can also use names instead of id here&lt;/p&gt;

&lt;h2&gt;
  
  
  Naming the docker containers
&lt;/h2&gt;

&lt;h3&gt;
  
  
  docker run —name custom-name image:version
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker run &lt;span class="nt"&gt;-p9000&lt;/span&gt;:6379 &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="nt"&gt;--name&lt;/span&gt; redis_latest redis
docker run &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="nt"&gt;-p9001&lt;/span&gt;:6379 &lt;span class="nt"&gt;--name&lt;/span&gt; redis_old redis:6.2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  docker rm container_id_or_name
&lt;/h2&gt;

&lt;p&gt;This command removes the container&lt;/p&gt;

&lt;p&gt;ex&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker &lt;span class="nb"&gt;rm &lt;/span&gt;redis_old redis_latest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Remove all containers
&lt;/h3&gt;

&lt;p&gt;💡&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker ps -q | xargs docker stop
docker ps -q | xargs docker rm
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  To get the interactive terminal of a container
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker &lt;span class="nb"&gt;exec&lt;/span&gt; &lt;span class="nt"&gt;-it&lt;/span&gt; container_id_or_name /bin/bash
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To exit the terminal simply Enter &lt;code&gt;exit&lt;/code&gt; &lt;/p&gt;

&lt;p&gt;Here &lt;code&gt;-it&lt;/code&gt; stands for interactive mode.&lt;/p&gt;

&lt;h2&gt;
  
  
  Docker Volumes
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Creating a Volume
&lt;/h3&gt;

&lt;p&gt;You can create a volume explicitly using the &lt;code&gt;docker volume create&lt;/code&gt; command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker volume create my-volume
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This creates a new volume named &lt;code&gt;my-volume&lt;/code&gt; that Docker will manage.&lt;/p&gt;

&lt;h3&gt;
  
  
  Running a Container with a Volume
&lt;/h3&gt;

&lt;p&gt;When running a container, you can mount the volume using the &lt;code&gt;-v&lt;/code&gt; or &lt;code&gt;--mount&lt;/code&gt; flag:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker run &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="nt"&gt;--name&lt;/span&gt; my-app &lt;span class="nt"&gt;-v&lt;/span&gt; my-volume:/app myapp:v1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This mounts the &lt;code&gt;my-volume&lt;/code&gt; volume to the &lt;code&gt;/app&lt;/code&gt; directory inside the container. Any data written to &lt;code&gt;/app&lt;/code&gt; will be stored in the &lt;code&gt;my-volume&lt;/code&gt; volume on the host.&lt;/p&gt;

&lt;h3&gt;
  
  
  Inspecting Volume Contents
&lt;/h3&gt;

&lt;p&gt;You can inspect the contents of the volume on the host machine. The exact location depends on your Docker storage driver, but typically it will be under &lt;code&gt;/var/lib/docker/volumes/&lt;/code&gt;. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;ls&lt;/span&gt; /var/lib/docker/volumes/my-volume/_data
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will list the files stored in the volume.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgeupom5rkp9mgj7ickwr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgeupom5rkp9mgj7ickwr.png" alt="Image description" width="800" height="457"&gt;&lt;/a&gt;## Persisting Data&lt;/p&gt;

&lt;p&gt;If the container crashes or is removed, the data written to the volume will persist on the host. You can then attach the volume to a new container to access the data:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker run &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="nt"&gt;--name&lt;/span&gt; new-app &lt;span class="nt"&gt;-v&lt;/span&gt; my-volume:/app myapp:v2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The new container will have access to the same data as the previous container.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sharing Volumes Between Containers
&lt;/h2&gt;

&lt;p&gt;Volumes can be mounted to multiple containers simultaneously. This allows containers to share data:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker run &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="nt"&gt;--name&lt;/span&gt; app1 &lt;span class="nt"&gt;-v&lt;/span&gt; my-volume:/data app1:v1
docker run &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="nt"&gt;--name&lt;/span&gt; app2 &lt;span class="nt"&gt;-v&lt;/span&gt; my-volume:/data app2:v1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Both &lt;code&gt;app1&lt;/code&gt; and &lt;code&gt;app2&lt;/code&gt; will have read-write access to the &lt;code&gt;/data&lt;/code&gt; directory which points to the &lt;code&gt;my-volume&lt;/code&gt; volume.&lt;/p&gt;

&lt;p&gt;Docker volumes provide a way to persist data outside the container lifecycle. This ensures important data is not lost when containers are removed or crash. Volumes can be shared between multiple containers and their contents can be inspected directly on the host.&lt;/p&gt;

&lt;p&gt;Thanks for making it to the very last. Since you read this do consider &lt;br&gt;
leaving some comments. &lt;/p&gt;

&lt;p&gt;Also you might find this post useful&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/oatula/making-backup-of-a-docker-volume-1la9"&gt;https://dev.to/oatula/making-backup-of-a-docker-volume-1la9&lt;/a&gt;&lt;/p&gt;

</description>
      <category>docker</category>
      <category>webdev</category>
      <category>devops</category>
    </item>
    <item>
      <title>Making backup of a docker volume</title>
      <dc:creator>Atul Anand Oraon</dc:creator>
      <pubDate>Sun, 31 Mar 2024 19:10:30 +0000</pubDate>
      <link>https://dev.to/oatula/making-backup-of-a-docker-volume-1la9</link>
      <guid>https://dev.to/oatula/making-backup-of-a-docker-volume-1la9</guid>
      <description>&lt;h2&gt;
  
  
  Making a backup of the database
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffcgko7wmuj7viiykr24v.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffcgko7wmuj7viiykr24v.jpeg" alt="Docker Volume img" width="800" height="800"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can use it for any type of container not just for the database.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;💡️ Don't be afraid of the --rm flag&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
It is not removing your container it just removes&lt;br&gt;&lt;br&gt;
🐧️&lt;code&gt;alpine Linux&lt;/code&gt; container for using the &lt;code&gt;cp&lt;/code&gt; command.&lt;br&gt;&lt;br&gt;
Which is a &lt;code&gt;Linux command&lt;/code&gt;  &lt;/p&gt;

&lt;p&gt;The command will be like this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;
docker run &lt;span class="nt"&gt;--rm&lt;/span&gt; &lt;span class="nt"&gt;-v&lt;/span&gt; volume_id:/volume &lt;span class="nt"&gt;-v&lt;/span&gt; /path/to/backup/directory:/backup alpine &lt;span class="nb"&gt;cp&lt;/span&gt; &lt;span class="nt"&gt;-a&lt;/span&gt; /volume/. /backup/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  SIMPLE Explanation
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;docker run&lt;/code&gt; : run a command in a new container.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;--rm&lt;/code&gt; : remove the container after it exits.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;-v volume_id:/volume&lt;/code&gt; : mount the volume with id &lt;code&gt;volume_id&lt;/code&gt; to &lt;code&gt;/volume&lt;/code&gt; in the container.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;-v /path/to/backup/directory:/backup&lt;/code&gt; : mount the host[our computer or server] directory &lt;code&gt;/path/to/backup/directory&lt;/code&gt; to &lt;code&gt;/backup&lt;/code&gt; in the container.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;alpine&lt;/code&gt; : the image to use, its a lightweight Linux image.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;cp -a /volume/. /backup/&lt;/code&gt; : copy the contents of the volume to the backup directory on the host machine where it is being run.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So if you run locally it will be on your computer else&lt;br&gt;&lt;br&gt;
it will be on the server if you run it on the server.&lt;/p&gt;

&lt;h3&gt;
  
  
  [BOOKISH EXPLANATION] Specific questions regarding the command
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;:/volume&lt;/code&gt; and &lt;code&gt;:/backup&lt;/code&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In the command &lt;code&gt;docker run --rm -v  7ade41ba2f490a4ccbe15b442baa7071a8bf57c4a0cb5cf250bbad845994ef4f:/volume -v /path/to/backup/directory:/backup alpine cp -a /volume/. /backup/&lt;/code&gt;,
the &lt;code&gt;:/volume&lt;/code&gt; and &lt;code&gt;:/backup&lt;/code&gt; parts indicate the mount points within the container.
When you use the &lt;code&gt;-v&lt;/code&gt; option with Docker, you specify the volume binding in the format &lt;code&gt;host_path:container_path&lt;/code&gt;.
So &lt;code&gt;7ade41ba2f490a4ccbe15b442baa7071a8bf57c4a0cb5cf250bbad845994ef4f:/volume&lt;/code&gt; means
you're mounting the Docker volume
&lt;code&gt;7ade41ba2f490a4ccbe15b442baa7071a8bf57c4a0cb5cf250bbad845994ef4f&lt;/code&gt; to &lt;code&gt;/volume&lt;/code&gt;
inside the container, and &lt;code&gt;/path/to/backup/directory:/backup&lt;/code&gt; means you're mounting
the host directory &lt;code&gt;/path/to/backup/directory&lt;/code&gt; to &lt;code&gt;/backup&lt;/code&gt; inside the container.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;code&gt;alpine&lt;/code&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;alpine&lt;/code&gt; is the name of the Docker image being used to run the temporary container.
In this case, it's an Alpine Linux image, which is commonly used due to its small size
and efficiency for tasks like this.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;code&gt;cp -a /volume/. /backup/&lt;/code&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;This is the &lt;code&gt;cp&lt;/code&gt; command that copies files.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;-a&lt;/code&gt; is an option that preserves the original attributes of the files being copied,
such as permissions and timestamps.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;/volume/&lt;/code&gt; is the source directory from which files are being copied.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;.&lt;/code&gt; at the end indicates that the entire contents of the source directory (including
hidden files) are being copied.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;/backup/&lt;/code&gt; is the destination directory where the files are being copied to.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;This command effectively mounts the Docker volume and a backup directory into an Alpine&lt;br&gt;&lt;br&gt;
Linux container, then copies the contents of the Docker volume to the backup directory&lt;br&gt;&lt;br&gt;
within the container. This allows you to create a backup of the data stored in the Docker volume.  &lt;/p&gt;

</description>
      <category>docker</category>
      <category>devops</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Setting the cookies using the JS, axios and expressJS</title>
      <dc:creator>Atul Anand Oraon</dc:creator>
      <pubDate>Sat, 02 Mar 2024 13:34:46 +0000</pubDate>
      <link>https://dev.to/oatula/setting-the-cookies-using-the-js-axios-47jf</link>
      <guid>https://dev.to/oatula/setting-the-cookies-using-the-js-axios-47jf</guid>
      <description>&lt;p&gt;Hi all&lt;br&gt;
recently I am learning about the auth.&lt;br&gt;
I tried setting the accessToken and refreshToken for the auth.&lt;/p&gt;

&lt;p&gt;Initially decided to use fetch for it. It did not work in my case. Exhausted all the combination of credentials.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="err"&gt;credentials:&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="err"&gt;credentials:include,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="err"&gt;etc.&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I was really pissed and sad for like 3-4 days.&lt;/p&gt;

&lt;p&gt;Finally decided to switch to axios also made some adjustment to my backend and it started working.&lt;/p&gt;

&lt;p&gt;Let me show you my code.&lt;/p&gt;

&lt;p&gt;My axios request&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;loginCall&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="c1"&gt;// You may get these data from the relevant selector&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;email&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;dummy@mail.com&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
        &lt;span class="na"&gt;password&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;123&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;options&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;method&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;POST&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Content-Type&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;application/json&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;},&lt;/span&gt;
      &lt;span class="na"&gt;withCredentials&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// Ensure Axios includes cookies in the request&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;

    &lt;span class="nf"&gt;axios&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;http://localhost:8002/auth/login&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;options&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Check if response status is in the 200 range&lt;/span&gt;
        &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;300&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;response is: &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

          &lt;span class="c1"&gt;// Print all headers from response&lt;/span&gt;
          &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;headers are: &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
          &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

          &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;responseData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
          &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;responseData&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

          &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;accessToken&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;responseData&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;accessToken&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
          &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;access token is: &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;accessToken&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

          &lt;span class="c1"&gt;// Set the accessToken cookie correctly&lt;/span&gt;
          &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cookie&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`accessToken=&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;accessToken&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;; path=/; SameSite=Strict; expires=&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;now&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;60&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;
          &lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;toUTCString&lt;/span&gt;&lt;span class="p"&gt;()}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
          &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;cookie is: &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cookie&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

          &lt;span class="c1"&gt;// The refreshToken HttpOnly cookie will be automatically stored by the browser&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Network response was not ok&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="p"&gt;})&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Put this in your index.js/server.js&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;express&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;express&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;express&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;cors&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;cors&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="nf"&gt;cors&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;origin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;localhost&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;credentials&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To add multiple domains do this.&lt;br&gt;
 &lt;code&gt;origin: ["http://localhost:3000", "http://example.com", "https://subdomain.example.com"]&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;now the below code in your&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;express&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;express&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;bcrypt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;bcrypt&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;jwt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;jsonwebtoken&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;User&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;../models/user-model&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Login Route with JWT&lt;/span&gt;
&lt;span class="nx"&gt;router&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/login&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;email&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;password&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="c1"&gt;// Check if user exists&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;User&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;findOne&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;email&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;

    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;401&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Authentication failed, email not found&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// Check password&lt;/span&gt;
    &lt;span class="c1"&gt;// @ts-ignore&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;isMatch&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;bcrypt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;compare&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;password&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;password&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;isMatch&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;401&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Authentication failed, wrong password&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// Generate JWT token with expiration time of 1 month (in seconds)&lt;/span&gt;
    &lt;span class="c1"&gt;// jwt.sign({ id user._id, exp Math.floor(Date.now() / 1000) + (60 * 60 * 24 * 30) }, SECRET);&lt;/span&gt;
    &lt;span class="c1"&gt;//@ts-ignore&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;accessToken&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;refreshToken&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;signToken&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="c1"&gt;// httpOnly token way for the deployment&lt;/span&gt;
    &lt;span class="c1"&gt;// res.cookie("accessToken", accessToken, {&lt;/span&gt;
    &lt;span class="c1"&gt;//   httpOnly: false,&lt;/span&gt;
    &lt;span class="c1"&gt;//   sameSite: "none",&lt;/span&gt;
    &lt;span class="c1"&gt;// });&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;expires&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;now&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;60&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;60&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;cookie&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;refreshToken&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;refreshToken&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;httpOnly&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;expires&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;expires&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;sameSite&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;none&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;

    &lt;span class="nx"&gt;res&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;201&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;User created successfully&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;accessToken&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;accessToken&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Server Error&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Pardon me for a lot of commented code. &lt;/p&gt;

&lt;p&gt;I have removed some yet some remains.&lt;/p&gt;

&lt;p&gt;So for me this code worked in the firefox browser&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;expires&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;now&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;60&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;60&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;cookie&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;refreshToken&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;refreshToken&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;httpOnly&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;expires&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;expires&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;sameSite&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;none&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
   &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;refresh Token sent&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For my friend using Brave browser the below code worked.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;expires&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;now&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;60&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;60&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;cookie&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;refreshToken&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;refreshToken&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;httpOnly&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;secure&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;expires&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;expires&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;sameSite&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;none&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;domain&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;localhost&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;})&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
        &lt;span class="na"&gt;accessToken&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;accessToken&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;role&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;role&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;firstname&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;firstname&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;lastname&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;lastname&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;email&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;email&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;User logged In Successfully&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now let me explain you these settings&lt;br&gt;
First of all you must add the origin and credentials. Its a must. Else your tokens won't be sent or set.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;expires&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;now&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;60&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;60&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cookie&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;refreshToken&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;refreshToken&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;httpOnly&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;secure&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;expires&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;expires&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;sameSite&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;none&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;domain&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;localhost&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now these cookie settings.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;path: /&lt;/code&gt; This means the cookie is valid across all the path.&lt;br&gt;
If you want this to be valid to certain parts only say&lt;br&gt;&lt;br&gt;
&lt;code&gt;/protected&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;httpOnly:true&lt;/code&gt; This option is very crucial here. It tells the browser don't allow any JS touch it. Which means its totally secure. This is protected from the &lt;strong&gt;Cross Origin Attack&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;secure:true&lt;/code&gt; This option means that browser will only send this cookie over https connection not http. &lt;br&gt;
My reccomendation is to make a variable named cookieOptions or refreshTokenOptions. &lt;/p&gt;

&lt;p&gt;Try setting the &lt;code&gt;secure:true&lt;/code&gt; in the production environment.&lt;br&gt;
As you will go nuts when your backend on local system does not &lt;br&gt;
get the cookies. As almost all of us have our local working on http.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;cookieOptions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;httpOnly&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;sameSite&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;none&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;NODE_ENVIRONMENT&lt;/span&gt;&lt;span class="o"&gt;==&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;production&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="nx"&gt;cookieOptions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;secure&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;expires&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;now&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;60&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;60&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nl"&gt;expires&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;expires&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This sets the expiry time for the cookie to 1 hour.&lt;br&gt;&lt;br&gt;
You can set the time as per your choice.&lt;br&gt;&lt;br&gt;
My personal reccomendations are 3hour to a day.&lt;br&gt;&lt;br&gt;
Not more than that.&lt;/p&gt;

&lt;p&gt;Also the time has to be given in miliseconds.&lt;br&gt;
So to set 1 hour = 60mins X 60sec X 1000 milisec&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sameSite: "none"&lt;/code&gt; is used to send the cookies cross-site requests,&lt;br&gt;&lt;br&gt;
which basically means your backend and client can be on different ports and even different addresses.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;domain: "localhost"&lt;/code&gt; means its valid for only for localhost domain.&lt;br&gt;
You may want to have multiple domains do it like this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;    &lt;span class="nx"&gt;domain&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;localhost&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;example.com&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;.subdomain.example.com&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="s2"&gt;```



&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>tutorial</category>
      <category>authjs</category>
    </item>
  </channel>
</rss>
