<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Hrishikesh Pathak on Medium]]></title>
        <description><![CDATA[Stories by Hrishikesh Pathak on Medium]]></description>
        <link>https://medium.com/@hrishikeshb2pathak?source=rss-a4a743f55d37------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*AOZn6yl67fqJ3rpfKwJK6w.jpeg</url>
            <title>Stories by Hrishikesh Pathak on Medium</title>
            <link>https://medium.com/@hrishikeshb2pathak?source=rss-a4a743f55d37------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 05:10:42 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@hrishikeshb2pathak/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Interface vs Abstract Class in Typescipt]]></title>
            <link>https://javascript.plainenglish.io/interface-vs-abstract-class-in-typescipt-a741264c275d?source=rss-a4a743f55d37------2</link>
            <guid isPermaLink="false">https://medium.com/p/a741264c275d</guid>
            <category><![CDATA[oop]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[typescript]]></category>
            <dc:creator><![CDATA[Hrishikesh Pathak]]></dc:creator>
            <pubDate>Tue, 11 Jul 2023 19:01:31 GMT</pubDate>
            <atom:updated>2023-07-12T01:05:11.414Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cfYweontEK3CNC1u9sd8Jw.png" /><figcaption>Hero image</figcaption></figure><p>In Typescript, interface, and abstract classes are used to define the structure or shape of an object(class). But there is some difference between the two.</p><p>In this article, we are going to look at what are the differences between interface and abstract class in typescript and what you should use in your typescript project.</p><h3>Interface in Typescript</h3><p>According to the official typescript documentation, <a href="https://www.typescriptlang.org/docs/handbook/interfaces.html">interfaces are a powerful way of defining contracts within code</a>.</p><p>For example, you have an interface called Child, where you have defined all the features of a child.</p><pre>interface Child {<br>  name: string;<br>  age: number;<br>  height: number;<br>  weight: number;<br>  getBMI(): number;<br>}</pre><p>Here I have added the name, age, height, and weight properties of a child and a method definition getBMI. <strong>Look closely</strong>, here I described only properties and methods in this Child interface. I haven&#39;t added any values or inner workings of the method.</p><p>Once a class implements this interface, all those properties and methods of the Child interface should be there in that class.</p><p>It means that interfaces make a <strong>blueprint</strong> about what an object or a class or a variable should look like if they implement an interface.</p><p>Interface forces an object to be in a particular shape.</p><p>Let’s see how to implement an interface in typescript.</p><pre>class Human implements Child {<br>  constructor(<br>    public name: string,<br>    public age: number,<br>    public height: number,<br>    public weight: number<br>  ) {}<br><br>  getBMI(): number {<br>    return this.weight / Math.pow(this.height, 2);<br>  }<br>}</pre><p>Here you can see, the Human class implements the Child interface completely. In addition to this, the Human class can add additional methods or properties on their own.</p><pre>class Human implements Child {<br>  constructor(<br>    public name: string,<br>    public age: number,<br>    public height: number,<br>    public weight: number,<br>    public surname:string<br>  ) {}<br><br>  getBMI(): number {<br>    return this.weight / Math.pow(this.height, 2);<br>  }<br><br>  get legalName():string{<br>    return `${this.name} ${this.surname}`<br>  }<br>}</pre><p>In the above example, you can see the surname and legalName getter set by the Human class, and the typescript compiler don&#39;t complain about that.</p><h3>Abstract Class in Typescript</h3><p>An abstract class is not very different from Interface in typescript. They also impose a structure on a child class who extends it.</p><p>Let’s convert our Child interface into an abstract class.</p><pre>abstract class Child {<br>  constructor(<br>    public name: string,<br>    public age: number,<br>    public height: number,<br>    public weight: number<br>  ) {}<br><br>  abstract getBMI(): number;<br>}</pre><p>When a class extends this abstract class, it must implement all the properties and methods declared in the Child abstract class.</p><pre>class Human extends Child {<br>  constructor(<br>    public name: string,<br>    public age: number,<br>    public height: number,<br>    public weight: number,<br>    public surname: string<br>  ) {<br>    super(name, age, height,weight)<br>  }<br><br>  getBMI(): number {<br>    return this.weight / Math.pow(this.height, 2);<br>  }<br><br>  get legalName(): string {<br>    return `${this.name} ${this.surname}`;<br>  }<br>}</pre><p>In addition to this, we can directly define the getBMI function in the abstract class itself.</p><pre>abstract class Child {<br>  constructor(<br>    public name: string,<br>    public age: number,<br>    public height: number,<br>    public weight: number<br>  ) {}<br><br>  getBMI(): number{<br>    return this.weight / Math.pow(this.height, 2); <br>  };<br>}</pre><p>Now remove the getBMI method from the Human object. But you can still access the method as the Human class extends the Child abstract class.</p><h3>Abstract class present at runtime</h3><p>The interface is a typescript addition to type-check your code efficiently. But on the contrary, an abstract class is a javascript feature and it is present at runtime.</p><p>Therefore you can access the abstract class in the runtime. Interfaces are removed from the code once your code is transpiled into javascript.</p><h3>Conclusion</h3><p>If you have read this blog to the end, you can say that there is not much difference between interfaces and abstract classes.</p><p>I only use the abstract class when I need to define a method inside the parent abstract class itself. Otherwise, I use Interfaces. Interfaces have less boilerplate and are more readable as compared to abstract classes.</p><p><em>Originally published at </em><a href="https://hrishikeshpathak.com/blog/interface-vs-abstract-class-typescript/"><em>https://hrishikeshpathak.com</em></a><em>.</em></p><p><em>More content at </em><a href="https://plainenglish.io/"><strong><em>PlainEnglish.io</em></strong></a><em>.</em></p><p><em>Sign up for our </em><a href="http://newsletter.plainenglish.io/"><strong><em>free weekly newsletter</em></strong></a><em>. Follow us on </em><a href="https://twitter.com/inPlainEngHQ"><strong><em>Twitter</em></strong></a>, <a href="https://www.linkedin.com/company/inplainenglish/"><strong><em>LinkedIn</em></strong></a><em>, </em><a href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw"><strong><em>YouTube</em></strong></a><em>, and </em><a href="https://discord.gg/GtDtUAvyhW"><strong><em>Discord</em></strong></a><strong><em>.</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a741264c275d" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/interface-vs-abstract-class-in-typescipt-a741264c275d">Interface vs Abstract Class in Typescipt</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to add filename to a code block in Astro blog]]></title>
            <link>https://medium.com/@hrishikeshb2pathak/how-to-add-filename-to-a-code-block-in-astro-blog-e0e91a4928e?source=rss-a4a743f55d37------2</link>
            <guid isPermaLink="false">https://medium.com/p/e0e91a4928e</guid>
            <category><![CDATA[jamstack]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[markdown]]></category>
            <category><![CDATA[code]]></category>
            <category><![CDATA[technical-writing]]></category>
            <dc:creator><![CDATA[Hrishikesh Pathak]]></dc:creator>
            <pubDate>Tue, 28 Feb 2023 15:07:12 GMT</pubDate>
            <atom:updated>2023-02-28T15:07:12.946Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*poJ66T7Ya8-JIdfe" /><figcaption>Photo by <a href="https://unsplash.com/@max_duz?utm_source=medium&amp;utm_medium=referral">Max Duzij</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Most of the time adding a filename in a code block gives context to a reader. It helps the reader decide which file is created or modified. A file name in the code block improves the reader experience multi-fold.</p><p>Now the question is how to add a filename inside a markdown code fence. Is it even possible with markdown?</p><p>So the answer is no. The default markdown spec doesn’t support passing anything other than the code language. Forget about passing the filename from the code fence.</p><p>But you can extend the markdown features using plugins. Astro uses <a href="https://github.com/remarkjs/remark">Remark to process the markdown files</a>. Therefore you can use the Remark and Rehype plugin with Astro with minimal configuration.</p><h3>Using remark-code-titles extension</h3><p>In this blog, I am using <a href="https://github.com/mottox2/remark-code-titles">remark-code-titles</a> plugin. This plugin parses the filename from the markdown code fence and displays it in the HTML document.</p><p>You can pass a file name using :filename notation to a code fence in the markdown file. This extension parses the markdown and extracts the filename from it. Then it displays the filename as a &lt;div&gt; element above the code block. In addition to this, it also applies remark-code-title class in every generated &lt;div&gt;. It makes the styling handier.</p><h4>Installation</h4><p>Let’s Install the remark-code-titles plugin <a href="https://www.npmjs.com/package/remark-code-titles">using npm</a>.</p><pre>npm i remark-code-titles</pre><h4>Configuration</h4><p>Now open the astro.config.mjs file in your project and modify the markdown configuration. This modification will also work for mdx files.</p><pre>import remarkCodeTitles from &quot;remark-code-titles&quot;;<br><br>export default defineConfig({<br>  markdown: { remarkPlugins: [remarkCodeTitles] },<br>  integrations: [<br>    mdx(),<br>  ],<br>});</pre><p>Here I add the remarkCodeTitles plugin as a remarkPlugins in the Astro configuration files.</p><h3>Usage in markdown and MDX document</h3><p>To use this plugin, open a new markdown or MDX document. Then add a code fence using 3 backticks. Then append the filename of the code block using :filename syntax. That’s it.</p><p>Now you can see an extra &lt;div&gt; element above your rendered code block which contain the filename. You can style the element using CSS by targeting the unique class remark-code-title.</p><h3>Conclusion</h3><p>In this blog, you have learned how to add a filename or title to a code block. This can be simply done using a remark plugin called remark-code-titles. Astro offers a very easy way to integrate Remark and Rehype plugins. Check the official Astro documentation to know more about markdown extensions.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e0e91a4928e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A better way to set up a Cloudflare worker project locally with Miniflare]]></title>
            <link>https://itnext.io/a-better-way-to-set-up-a-cloudflare-worker-project-locally-with-miniflare-596bb69ecc53?source=rss-a4a743f55d37------2</link>
            <guid isPermaLink="false">https://medium.com/p/596bb69ecc53</guid>
            <category><![CDATA[cloudflare-workers]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[cloudflare]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Hrishikesh Pathak]]></dc:creator>
            <pubDate>Sun, 29 Jan 2023 15:46:39 GMT</pubDate>
            <atom:updated>2023-01-29T18:29:13.601Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*gzj93FiR0Bclg0fz1t8Zkw.png" /></figure><p>Cloudflare worker is a serverless computing platform offered by Cloudflare. Unlike other serverless platforms like AWS Lambda or google cloud function, Cloudflare worker has a 0ms cold start. Which makes your code runs almost instantly when a request comes.</p><p>Cloudflare workers leverage the global Cloudflare infrastructure and deploy your script in every region of the world. Once you publish your worker script Cloudflare ensures you have the same superfast speed irrespective of your user location and the amount of your traffic.</p><p>In addition to all these features, Cloudflare worker is also paired with serverless edge storage called workers KV which is equally responsive to Cloudflare worker. If you have a read-heavy application and don’t want to waste time on maintaining servers, then Cloudflare worker may be the perfect choice for you.</p><h3>Install Miniflare to start developing worker scripts locally</h3><p>As far as we have discussed many positive features of Cloudflare workers that it seems almost irresistible to try out this service. But the primary roadblock for Cloudflare workers is its developer experience.</p><p>Cloudflare provides you with a very nice CLI tool called wrangler to develop your worker script and publish it on the Cloudflare platform. But wrangler should constantly be connected with Cloudflare servers and requires a steady internet connection to work.</p><p>It is a major setback for developers who want a nice and responsive developer experience to build new things with workers. The responsiveness of the wrangler project is compromised due to network latency. Now the obvious question that comes to your mind should be, <strong>”is there any solution to this problem? Can I improve my Cloudflare worker development experience?”</strong></p><p>Recently Cloudflare introduces Miniflare. As its name suggests, Miniflare is a feature-rich but miniature version of Cloudflare worker. Miniflare is a simulator that provides an environment for developing and testing Cloudflare worker scripts locally. Miniflare is written in typescript and supports most of the Cloudflare worker features like the KV database, durable objects, WebSockets, etc.</p><p>In addition to all these features, miniflare is fully local and works without an internet connection. It can instantly reload the server on code changes and provide an all-rounded developer experience.</p><p>To install miniflare in your project, first scaffold a Nodejs project inside a directory by running:</p><pre>npm init -y</pre><p>Now install the miniflare package by simply installing the miniflare package from npm as a development dependency.</p><pre>npm i -D miniflare</pre><p>Open your package.json file and add &quot;main&quot;:&quot;./src/index.js&quot; field. This helps miniflare to decide which JavaScript file to run when you start your miniflare server.</p><pre>{<br> &quot;name&quot;:&quot;miniflare project&quot;,<br> &quot;version&quot;:&quot;1.0.0&quot;,<br> &quot;main&quot;:&quot;./src/index.js&quot;<br>}</pre><p>Let’s add a script to our package.json file to run the miniflare server in watching mode. This script restarts our server when some code change and make our development faster.</p><pre>{<br> …<br> &quot;scripts&quot;: {<br> &quot;dev&quot;: &quot;miniflare -w&quot;,<br> },<br> …<br>}</pre><p>After all the initial setup is complete, let’s write your first hello world worker and run using miniflare.</p><h3>Write your first hello world Cloudflare Worker script</h3><p>First, create a src directory in your project root and then create an index.js file. Cloudflare Worker supports javascript by default. They choose javascript because javascript runs on a secure sandboxing environment by default.</p><p>But if you are not very familiar with javascript, you can also write worker scripts using C, C++, and rust language and compile them into a web assembly. Cloudflare workers can run web assembly code, but this method posed a toll on the performance. Please keep that in mind.</p><p>Inside our index.js file, we create a fetch event listener. When a user requests the server, the fetch event is triggered and the callback function within it is executed. It is very similar to front-end javascript code.</p><p>Inside the callback function, we create a Response object and send it back to the user using the event.respondWith method.</p><pre>addEventListener(&quot;fetch&quot;, (event) =&gt; {<br> event.respondWith(new Response(&quot;Hello world&quot;));<br>});</pre><p>To run this code, in your terminal run the npm run dev command. It calls the miniflare server to start and watch for any file change. Miniflare server starts in port 8787 and you can access it from your browser by visiting the <a href="http://localhost:8787`">http://localhost:8787</a> address.</p><p>Congratulations🎉! You have made your first Cloudflare worker script.</p><h3>Return JSON response from Cloudflare Worker</h3><p>If you are making a REST API server using Cloudflare worker, then it is more sensible to send a JSON response to the client rather than some plain text.</p><p>In Cloudflare worker, to send JSON response, you have to set the content-type header to application/json;charset=UTF-8. Thus the client understands that a JSON response is coming from the server.</p><p>In addition to setting the header, you should also send a valid JSON object as a response so that the client can parse and extract the data easily. In JavaScript, we can use the JSON.stringify method to convert an object into a valid JSON string.</p><pre>addEventListener(&quot;fetch&quot;, (event) =&gt; {<br> event.respondWith(<br>   new Response(JSON.stringify({ msg: &quot;Hello world&quot; }), {<br>     headers: {<br>       &quot;content-type&quot;: &quot;application/json;charset=UTF-8&quot;,<br>     },<br>     status: 200,<br>   })<br> );<br>});</pre><p>In the above example, I respond to the incoming request with a JSON object. The first parameter in the Response object is always the body and after that, you can define your headers.</p><p>In addition to the headers, I have also sent a status code. This is completely optional and you can omit this entirely.</p><h3>How to make network requests using Cloudflare worker</h3><p>If you intend to communicate other services from Cloudflare worker, you can easily achieve this functionality using the fetch API. You can use the fetch API to make an HTTP request from Cloudflare Worker. If you have used the fetch method from the browser before, then this is completely alike.</p><p>For demonstration, I am sending a GET request to a <a href="https://jsonplaceholder.typicode.com/users">placeholder REST API endpoint</a>. But you can make any type of request using the fetch API. If you are not very familiar with fetch, then this is a very <a href="https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch">intuitive guide from MDN</a> that covers how to use fetch to make an HTTP request from your browser.</p><p>We all know that network requests are async in nature. We have to wait a bit before expecting a response from the remote server. But the callback function inside the fetch event listener in Cloudflare Worker don’t support the async and await keyword.</p><p>Therefore, we need to make a separate async function that returns a Promise&lt;Response&gt;. Then we call the function from the event.respondWith() method.</p><p>Before making any external HTTP request, let’s break down our previous code into 2 separate functions. We also use the async keyword in the new function and call from the event.respondWith() method.</p><pre>addEventListener(&quot;fetch&quot;, (event) =&gt; {<br> const request = event.request;<br> event.respondWith(handleRequest(request));<br>});<br>async function handleRequest(request) {<br> return new Response(JSON.stringify({ msg: &quot;Hello world&quot; }), {<br>   headers: {<br>     &quot;content-type&quot;: &quot;application/json;charset=UTF-8&quot;,<br>   },<br>   status: 200,<br> });<br>}</pre><p>Here the handleRequest function is asynchronous. It takes a request argument and returns a Response with a proper header and status code. Inside the callback function, I call this handleRequest function and pass the request from the event.request method.</p><p>I think the concept of using asynchronous JavaScript in Cloudflare Worker is now clear to you. Let’s make another function called sendHttpRequest which handles all the fetch API logic and return a formatted JSON response.</p><pre>const sendHttpRequest = async () =&gt; {<br> try {<br>   const response = await fetch(&quot;https://jsonplaceholder.typicode.com/users&quot;);<br>   const jsonResponse = await response.json();<br>   return jsonResponse[0];<br> } catch (error) {<br>   console.error(error);<br> }<br>};</pre><p>The demo URL <a href="https://jsonplaceholder.typicode.com/users%60">https://jsonplaceholder.typicode.com/users</a> returns a list of dummy users. In the code, I only return the first user by using jsonResponse[0]. If you want, you can dump the entire response or do some modifications from your side.</p><p>Now inside the handleRequest function, create a new Response with proper headers and status code. Then encode the object returned from sendHttpRequest function and send it back to the user.</p><pre>async function handleRequest(request) {<br> return new Response(JSON.stringify(await sendHttpRequest()), {<br>   headers: {<br>     &quot;content-type&quot;: &quot;application/json;charset=UTF-8&quot;,<br>   },<br>   status: 200,<br> });<br>}</pre><p>Now run the miniflare server using the npm run dev command and visit <a href="http://localhost:8787`">http://localhost:8787</a> from your browser. You can see dummy user details in your browser.</p><h3>Add CORS headers in Cloudflare Worker response</h3><p>CORS or <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS">Cross Origin Resource Sharing</a> is not allowed in your browser. Browsers put this restriction for a very good reason. It enhances your online security and only allows connections from the same origin. Simply, if you are visiting foo.com, your front-end website can’t connect to any random servers, which URL is different from the foo.com/* scheme.</p><p>But assume you have a hosted API with a different domain name and you want to connect with it from your front-end application. In this scenario, you can explicitly allow the front-end website to access your site content by configuring your CORS headers.</p><p>To set CORS headers on your Cloudflare Worker response, you have to modify Access-Control headers and customize them as per your own needs. If you want to allow some specific domains, you can define them in the Access-Control-Allow-Origin header. If you want to make your API public and want to let any website connect to your server, just set * in the Access-Control-Allow-Origin header. Let’s see how to use this concept in code.</p><pre>const corsHeaders = {<br> &quot;Access-Control-Allow-Origin&quot;: &quot;*&quot;,<br> &quot;Access-Control-Allow-Methods&quot;: &quot;*&quot;,<br> &quot;Access-Control-Max-Age&quot;: &quot;86400&quot;,<br>};<br>async function handleRequest(request) {<br> return new Response(JSON.stringify(await sendHttpRequest()), {<br>   headers: {<br>   …corsHeaders,<br>   &quot;Access-Control-Allow-Headers&quot;: request.headers.get(&quot;Access-Control-Request-Headers&quot;<br>   ),<br>   &quot;content-type&quot;: &quot;application/json;charset=UTF-8&quot;,<br>   },<br>   status: 200,<br> });<br>}</pre><p>Here you can see, I have set wildcard * to Access-Control-Allow-Origin and Access-Control-Allow-Methods headers. This implies that any domain with any type of HTTP request can connect to my server.</p><h3>Build your Cloudflare Worker project using esbuild</h3><p>When your worker script becomes very long and complex, developers like you and me find it very hard to manage the code itself. Using esbuild with Cloudflare Worker, you can separate your code into different files.</p><p>Esbuild enables you to use standard Javascript import and export syntax to pass utility functions across the files. At the build time, esbuild takes all those files and creates a single minimal file optimized to run on Cloudflare Worker.</p><p>To install esbuild in your Worker project, run the following command.</p><pre>npm i -D esbuild</pre><p>Open your package.json file and modify the main and scripts fields to add esbuild in your build process.</p><pre>{<br> &quot;name&quot;:&quot;miniflare project&quot;,<br> &quot;version&quot;:&quot;1.0.0&quot;,<br> &quot;main&quot;:&quot;./dist/index.js&quot;,<br> &quot;scripts&quot;:{<br> &quot;dev&quot;: &quot;miniflare -w&quot;,<br> &quot;build&quot;: &quot;esbuild - bundle - sourcemap - outdir=dist ./src/index.js&quot;<br> }<br>}</pre><p>From now on, when you run the npm run build command, esbuild will take all the files inside the src directory and export the build into the dist directory.</p><h3>Deploy Cloudflare Worker using wrangler CLI</h3><p>After you finish building your Cloudflare Worker script, now it is high time to deploy the worker script. Cloudflare provides a nice tool for this task called wrangler. Using wrangler, you can easily configure your deployment from your terminal.</p><p>First, install the wrangler package using npm as a dev-dependency.</p><pre>npm i -D wrangler</pre><p>To create a new wrangler project, use the wrangler init command. If you want to generate a default wrangler project, use this command with a — yes flag.</p><pre>npx wrangler init - yes</pre><p>The above command creates a new Worker typescript project with testing files using Vitest. If you want to keep your project simple and don’t want to add any typescript and testing, just avoid the — yes flag.</p><p>Now open your wrangler.toml file and customize the name and main field as per your need. Here I change the main field to dist/index.js, as esbuild saves the build output in the dist directory.</p><pre>name = &quot;first-script&quot;<br>main = &quot;dist/index.js&quot;<br>compatibility_date = &quot;2023–01–21&quot;</pre><p>Now add a build command inside the wrangler.toml file. This build command will run when we run the wrangler publish command from our terminal.</p><pre>name = &quot;first-script&quot;<br>main = &quot;dist/index.js&quot;<br>compatibility_date = &quot;2023–01–21&quot;<br>[build]<br>command = &quot;npm run build&quot;<br>[build.upload]<br>format = &quot;service-worker&quot;</pre><p>At last, add the wrangler publish command as a script in your package.json file.</p><pre>&quot;scripts&quot;: {<br> &quot;dev&quot;: &quot;miniflare -w&quot;,<br> &quot;build&quot;: &quot;esbuild - bundle - sourcemap - outdir=dist ./src/index.js&quot;,<br> &quot;deploy&quot;: &quot;wrangler publish&quot;<br>},</pre><p>Now when you run the npm run deploy command, wrangler will run esbuild to build our local miniflare project and saves it into the dist directory. Then wrangler will authenticate your local project and publish the build to their servers.</p><h3>Conclusion</h3><p>In this blog, we have discussed the use of miniflare, esbuild, and wrangler to streamline our Cloudflare Worker development workflow. By following this tutorial, you can develop and deploy your worker within minutes. This also provides a very strong local development environment.</p><p>From now on, you are not dependent on a stable internet connection to develop and test your worker script. It increases your productivity as a developer and gives you a very nice development experience.</p><p>If you want to know how to deploy a static site using Cloudflare worker, then please read <a href="https://hrishikeshpathak.com/blog/deploy-nextjs-cloudflare-pages/">How to deploy Next.js app on Cloudflare pages</a>. You can <a href="https://twitter.com/hrishikshpathak">follow me on Twitter</a> for the latest blog updates or subscribe to my newsletter for more.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=596bb69ecc53" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/a-better-way-to-set-up-a-cloudflare-worker-project-locally-with-miniflare-596bb69ecc53">A better way to set up a Cloudflare worker project locally with Miniflare</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to install BKChem in Ubuntu 22.04 Linux]]></title>
            <link>https://medium.com/@hrishikeshb2pathak/how-to-install-bkchem-in-ubuntu-20-04-linux-d4ab56d7bf53?source=rss-a4a743f55d37------2</link>
            <guid isPermaLink="false">https://medium.com/p/d4ab56d7bf53</guid>
            <category><![CDATA[structure]]></category>
            <category><![CDATA[chemistry]]></category>
            <category><![CDATA[diagrams]]></category>
            <dc:creator><![CDATA[Hrishikesh Pathak]]></dc:creator>
            <pubDate>Tue, 20 Jul 2021 14:13:11 GMT</pubDate>
            <atom:updated>2022-06-07T16:05:12.856Z</atom:updated>
            <content:encoded><![CDATA[<p>If you are a chemistry student and want to draw some 2-dimensional chemical structure, you can use <a href="http://bkchem.zirael.org/">BKChem</a> software.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Pu1SK2jdkN1On5-Yh10cxA.png" /></figure><p>This is a free and open source software, and you can modify and distribute this software without any licensing issue.</p><p>To install this software in ubuntu 20.04 or any modern Linux distribution, please follow these steps.</p><h4>Step 1 : Check what python version you have in your device</h4><p>Bk Chem is written in python and to run this software, you want python in your device. But this software depends on python 2 instead of python 3. So at first, check if you have python 2 or python 3 in your device. In your terminal, execute the following command.</p><pre>python3 --version</pre><p>If the output is like <strong><em>Python 3.10.4, </em></strong>then you have python3 installed. To install python 2 in your device, execute this 2 commands in your terminal.</p><pre>sudo apt update</pre><pre>sudo apt install python2</pre><h4>Step2 : Download BKChem package</h4><p>Go to this <a href="https://bkchem.zirael.org/download/bkchem-0.13.0.tar.gz">link</a> and download BKChem package. This is a tar.gz file. To extract this file, you can use your file manager. Right-click on the compressed file and choose “Extract here” option.</p><p>If you want to extract this file with your terminal, then go to the directory which contain your compressed file and execute the following commands.</p><pre>tar -xf yourBkChemFileName.tar.gz -C ./bkChem-latest</pre><p>In this command, replace “YourBKChemFileName” with your downloaded package. This command extract your package and put the content in <strong>bkChem-latest</strong> directory.</p><h4>Step 3 : Install dependency</h4><p>BKChem software have two critical dependency we have to fulfil. We have to install <strong>python-pmw</strong> and <strong>python-cairo</strong> package.</p><pre>sudo apt install python-pmw</pre><pre>sudo apt install python-cairo</pre><h4>Step 4 : Run BKChem software</h4><p>As we have extracted BKChem software in the <strong>bkChem-latest</strong> folder previously, locate to that folder and find <strong>bkchem</strong> folder inside.</p><p>Open a terminal in that <strong>bkchem</strong> folder. Type ls to see the content of that folder. See if this folder contains <strong>bkchem.py</strong> file.</p><p>Then run the following command to start your BKChem software.</p><pre>python2 bkchem.py</pre><p>Your software should start by this command. If you find any error, please make sure that you have <strong>bkchem.py</strong> file in <strong>bkchem</strong> folder.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d4ab56d7bf53" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>