<?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[Excited Developers - Medium]]></title>
        <description><![CDATA[We are a group of developers who love technologies and more than that we love explain these techs in layman terms. We dont have an email id yet but you can reach out us through comment section. And yeah we do have a name Eximdevs :) - Medium]]></description>
        <link>https://medium.com/excited-developers?source=rss----1fdbd0a55dc8---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Excited Developers - Medium</title>
            <link>https://medium.com/excited-developers?source=rss----1fdbd0a55dc8---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 07:04:13 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/excited-developers" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Java Multithreading — All you need to know]]></title>
            <link>https://medium.com/excited-developers/java-multithreading-all-you-need-to-know-33d7e0ff4622?source=rss----1fdbd0a55dc8---4</link>
            <guid isPermaLink="false">https://medium.com/p/33d7e0ff4622</guid>
            <category><![CDATA[multithreading]]></category>
            <category><![CDATA[thread-safety]]></category>
            <category><![CDATA[concurrency]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[java-thread]]></category>
            <dc:creator><![CDATA[Ashish]]></dc:creator>
            <pubDate>Thu, 15 Jun 2023 07:17:00 GMT</pubDate>
            <atom:updated>2023-06-27T13:45:51.201Z</atom:updated>
            <content:encoded><![CDATA[<h3>Java Multithreading — All you need to know</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9kOKwmKfiiYXHKR_nBCM6g.png" /><figcaption>Source: Unknown</figcaption></figure><h4>The only blog that you will ever need. Let’s get started</h4><p>Authors: <a href="https://medium.com/u/f38880efbba8">Ashish Pandey</a> (<a href="https://www.linkedin.com/in/ashish-pandey01/">LinkedIn</a>) and <a href="https://medium.com/u/8daa50128e26">sagar sharma</a> (<a href="https://www.linkedin.com/in/sagar243/">LinkedIn</a>)</p><p>The below table gives a brief about the available methods through which we can multithreading in java. We will dive down in each of them in detail with code samples going ahead.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*140YkFAXW97UX5QqnoHYig.png" /></figure><ul><li><strong>Thread class</strong>: The Thread class is the most basic way to create a thread in Java. It provides a simple interface for creating and managing threads. To create a thread using the Thread class, you need to create a new instance of the Thread class and then call the start() method on the instance. The start() method will start the thread running.</li></ul><p>The Thread class also provides a number of methods for managing threads, such as the join() method, which will wait for the thread to finish running, and the sleep() method, which will pause the thread for a specified amount of time.</p><ul><li><strong>Runnable interface</strong>: The Runnable interface is a more powerful way to create a thread in Java. It provides a way to create a thread that performs a task that is defined by a separate class. To create a thread using the Runnable interface, you need to create a new class that implements the Runnable interface and then override the run() method in the class. The run() method is where you will define the task that the thread will perform.</li></ul><p>To create a thread using the Runnable interface, you need to create a new instance of the Thread class and then pass an instance of the class that implements the Runnable interface to the constructor of the Thread class. The start() method will then start the thread running.</p><ul><li><strong>Callable interface</strong>: The Callable interface is another powerful way to create a thread in Java. It provides a way to create a thread that returns a value. To create a thread using the Callable interface, you need to create a new class that implements the Callable interface and then override the call() method in the class. The call() method is where you will define the task that the thread will perform.</li></ul><p>To create a thread using the Callable interface, you need to create a new instance of the ExecutorService class and then call the submit() method on the instance, passing an instance of the class that implements the Callable interface to the method. The submit() method will return a Future object, which you can use to get the value that the thread returns.</p><ul><li><strong>ExecutorService</strong>: The ExecutorService class is a powerful way to create and manage a pool of threads. It provides a number of methods for creating and managing threads, such as the submit() method, which will submit a task to the pool, and the awaitTermination() method, which will wait for all of the tasks in the pool to finish running.</li></ul><p>The ExecutorService class is a good choice when you need to create a pool of threads that can be reused. For example, if you need to create a pool of threads that will download images from the internet, you can use the ExecutorService class to create the pool of threads and then submit the download tasks to the pool. The ExecutorService class will take care of creating and managing the threads, and you can focus on writing the code that performs the downloads.</p><ul><li><strong>ForkJoinPool</strong>: The ForkJoinPool class is a specialized type of ExecutorService that is designed for performing a large number of small, independent tasks. It is very efficient at using resources, and it can be used to perform tasks such as sorting a large array or searching for a value in a large database.</li><li><strong>CompletableFuture</strong>: The CompletableFuture class is a powerful class that provides a way to create and manage a future that represents the completion of a task. It can be used to coordinate the execution of multiple tasks, and it provides a number of methods for getting the result of a task, checking the status of a task, and waiting for a task to finish.</li></ul><p>The CompletableFuture class is a good choice when you need to coordinate the execution of multiple tasks. For example, if you need to download an image and then resize it, you can use the CompletableFuture class to coordinate the execution of the download task and the resize task. The CompletableFuture class will take care of making sure that the tasks are executed in the correct order, and it will provide you with a way to get the result of the tasks.</p><h4>What happens when you provide more tasks than the threads can handle?</h4><p>If you provide more tasks than the threads can handle, <strong><em>the threads will start to queue up</em></strong>. The first thread will start running, and when it finishes, the next thread in the queue will start running. This will continue until all of the tasks have been completed.</p><p>The number of tasks that a thread can handle depends on a number of factors, such as the complexity of the tasks, the amount of memory that the tasks use, and the amount of CPU time that the tasks require.</p><p>If you are providing more tasks than the threads can handle, you may want to consider using a thread pool. A thread pool is a group of threads that are managed by the Java runtime environment. When you submit a task to a thread pool, the thread pool will start a new thread to execute the task. If there are no available threads in the pool, the task will be queued up. When a thread becomes available, the task will be executed.</p><p>Thread pools can help to improve the performance of your application by ensuring that there are always threads available to execute tasks. They can also help to improve the scalability of your application by allowing you to handle more tasks without having to create more threads.</p><p>Let’s say you have an application that is downloading images from the internet. You could use a single thread to download the images, but this would be very slow. Instead, you could use multiple threads to download the images. This would speed up the download process because the images could be downloaded in parallel. However, if you use too many threads, you could actually slow down the download process. This is because each thread would need to share the CPU and memory resources on the computer. If there are not enough CPU and memory resources available, the threads will start to compete for resources, which will slow down the download process.</p><h3>Managing queue size for each method</h3><p><strong>Managing queue size can be crucial in multithreading to prevent resource starvation and overload.</strong> Here are some ways to manage queue size in different threading approaches:</p><p>1.<strong>Thread Class:</strong> The Thread class has no built-in support for queue size management. However, you can manually manage the queue size by implementing a bounded buffer or using a BlockingQueue to limit the number of tasks that can be submitted to a thread at a time.</p><p>2. <strong>Runnable Interface:</strong> Similar to the Thread class, the Runnable interface has no built-in support for queue size management. However, you can manually manage the queue size as mentioned above.</p><pre>class BoundedBuffer {<br>    private int[] buffer;<br>    private int size, count, head, tail;<br><br>    public BoundedBuffer(int size) {<br>        buffer = new int[size];<br>        this.size = size;<br>        count = 0;<br>        head = 0;<br>        tail = 0;<br>    }<br><br>    public synchronized void put(int value) throws InterruptedException {<br>        while (count == size) {<br>            wait();<br>        }<br>        buffer[tail] = value;<br>        tail = (tail + 1) % size;<br>        count++;<br>        notifyAll();<br>    }<br><br>    public synchronized int take() throws InterruptedException {<br>        while (count == 0) {<br>            wait();<br>        }<br>        int value = buffer[head];<br>        head = (head + 1) % size;<br>        count--;<br>        notifyAll();<br>        return value;<br>    }<br>}<br><br>class Task implements Runnable {<br>    private BoundedBuffer queue;<br><br>    public Task(BoundedBuffer queue) {<br>        this.queue = queue;<br>    }<br><br>    public void run() {<br>        try {<br>            int value = queue.take();<br>            // process the value<br>        } catch (InterruptedException e) {<br>            Thread.currentThread().interrupt();<br>        }<br>    }<br>}<br><br>public class Main {<br>    public static void main(String[] args) {<br>        int numTasks = 1000;<br>        BoundedBuffer queue = new BoundedBuffer(100);<br><br>        for (int i = 0; i &lt; numTasks; i++) {<br>            Runnable task = new Task(queue);<br>            new Thread(task).start();<br>        }<br>    }<br>}</pre><pre>To catch unhandled exceptions in threads, <br>you can also use Thread.UncaughtExceptionHandler like this:<br><br>Thread thread = new Thread(new MyRunnable());<br>thread.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {<br>    @Override<br>    public void uncaughtException(Thread t, Throwable e) {<br>        // handle the uncaught exception<br>    }<br>});<br>thread.start();</pre><p>3. <strong>Callable Interface:</strong> The Callable interface can be used with an ExecutorService to submit a task to a thread pool. You can create an ExecutorService with a fixed thread pool size and a bounded blocking queue to limit the number of tasks that can be submitted to the thread pool. This way, once the queue is full, the new tasks will wait until there is room in the queue.</p><pre>import java.util.concurrent.*;<br><br>public class CallableExample {<br>    public static void main(String[] args) {<br>        int numThreads = 4;<br>        BlockingQueue&lt;Future&lt;String&gt;&gt; queue = new LinkedBlockingQueue&lt;&gt;(numThreads);<br><br>        ExecutorService executorService = Executors.newFixedThreadPool(numThreads);<br><br>        for (int i = 0; i &lt; numThreads; i++) {<br>            Future&lt;String&gt; future = executorService.submit(new Task());<br>            queue.add(future);<br>        }<br><br>        while (!queue.isEmpty()) {<br>            try {<br>                Future&lt;String&gt; future = queue.take();<br>                String result = future.get();<br>                System.out.println(result);<br>            } catch (InterruptedException | ExecutionException e) {<br>                System.err.println(&quot;Error occurred while executing task: &quot; + e.getMessage());<br>            }<br>        }<br><br>        executorService.shutdown();<br>    }<br><br>    private static class Task implements Callable&lt;String&gt; {<br>        @Override<br>        public String call() throws Exception {<br>            // Your code to execute the task<br>            return &quot;Task completed successfully&quot;;<br>        }<br>    }<br>}</pre><p>4. ExecutorService: The ExecutorService provides a built-in queue to manage the task queue size. You can set the queue size using the BlockingQueue parameter when creating an ExecutorService instance. The default implementation of the BlockingQueue is an unbounded queue, which can lead to memory issues if too many tasks are submitted. Important functions</p><ul><li>setCorePoolSize(): This method sets the minimum number of threads that are always kept in the pool, even if there are no tasks to be executed.</li><li>setMaximumPoolSize(): This method sets the maximum number of threads that can be in the pool at any given time.</li><li>getCorePoolSize(): This method gets the minimum number of threads that are always kept in the pool, even if there are no tasks to be executed.</li><li>getMaximumPoolSize(): This method gets the maximum number of threads that can be in the pool at any given time.</li><li>getQueue(): This method gets the queue that is used to store the tasks that are waiting to be executed.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*--X7u77BnUE1pQAIiNjW8w.png" /></figure><blockquote><em>Also read about ThreadPoolExecutorFactoryBean, ThreadPoolTaskScheduler, and ScheduledExecutorFactoryBean.</em></blockquote><pre>import org.springframework.core.task.TaskExecutor;<br><br>public class MyTaskExecutor implements TaskExecutor {<br><br>    private final ThreadPoolTaskExecutor executor;<br><br>    public MyTaskExecutor() {<br>        executor = new ThreadPoolTaskExecutor();<br>        executor.setCorePoolSize(10);<br>        executor.setMaxPoolSize(100);<br>        executor.setQueueCapacity(25);<br>        executor.setThreadNamePrefix(&quot;MyThread-&quot;);<br>        executor.initialize();<br>    }<br><br>    @Override<br>    public void execute(Runnable task) {<br>        executor.execute(task);<br>    }<br><br>}<br>//To use MyTaskExecutor<br>private ThreadPoolTaskExecutor myTaskExecutor;<br><br>public void someMethod() {<br>    myTaskExecutor.execute(new Runnable() {<br>        @Override<br>        public void run() {<br>            // Do some work here<br>        }<br>    });<br>}</pre><p>Some corner cases that we need to be aware of while using an executor service:</p><ol><li>Task dependency: If the tasks are dependent on each other, we need to ensure that they are executed in the right order. For example, if we have two tasks A and B, where B is dependent on A, we need to ensure that A is executed before B.</li><li>Task timeouts: We need to handle cases where a task may take too long to complete. We can set a timeout value for the tasks to ensure that they do not run indefinitely.</li><li>Task exceptions: We need to handle cases where a task may throw an exception. We can use a try-catch block to catch the exception and handle it appropriately.</li><li>Task cancellation: We need to handle cases where a task may need to be cancelled. We can use the Future interface to cancel a task.</li><li>Resource management: We need to ensure that the executor service does not consume too many resources such as memory, CPU, or network bandwidth. We can set limits on the number of threads or the size of the thread pool to manage resource usage.</li><li>Deadlock: We need to be careful while implementing tasks that may lead to a deadlock situation. For example, if two tasks are waiting for each other to complete, it can lead to a deadlock. We can avoid this by using a timeout or a timeout handler.</li><li>Thread safety: We need to ensure that the tasks and the resources accessed by them are thread-safe. For example, if two tasks are accessing the same resource concurrently, it may lead to data corruption or other issues.</li></ol><pre>Some ways to handle variuos corner cases:<br><br>RejectedExecutionException: <br>This occurs when the ExecutorService&#39;s task queue is full <br>and cannot accept any more tasks. To handle this, <br>you can catch the exception and either retry the task later <br>or notify the user that the task could not be executed.<br><br>try {<br>    executorService.submit(task);<br>} catch (RejectedExecutionException e) {<br>    // Handle the exception<br>}<br><br>TimeoutException: <br>This occurs when a task exceeds its timeout period before it is completed.<br><br>try {<br>    Future&lt;T&gt; future = executorService.submit(task);<br>    T result = future.get(1, TimeUnit.SECONDS);<br>} catch (TimeoutException e) {<br>    // Handle the exception<br>}<br><br>ExecutionException: <br>This occurs when an exception is thrown while executing a task.<br><br>try {<br>    Future&lt;T&gt; future = executorService.submit(task);<br>    T result = future.get();<br>} catch (ExecutionException e) {<br>    // Handle the exception<br>}</pre><p>5. <strong>ForkJoinPool:</strong> The ForkJoinPool class has built-in support for queue size. management. You can set the maximum queue size using the ForkJoinPool.ForkJoinWorkerThreadFactory class. The default queue size is unbounded, which can lead to memory issues if too many tasks are submitted.</p><ul><li>setParallelism(): This method sets the number of threads that are used to execute tasks in the pool.</li><li>getParallelism(): This method gets the number of threads that are used to execute tasks in the pool.</li><li>getQueue(): This method gets the queue that is used to store the tasks that are waiting to be executed.</li></ul><pre>import java.util.concurrent.*;<br><br>public class ForkJoinPoolExample {<br>    public static void main(String[] args) {<br>        <br>        // Create a ForkJoinPool with parallelism level 4<br>        ForkJoinPool forkJoinPool = new ForkJoinPool(4);<br><br>        // Submit a task to the ForkJoinPool<br>        forkJoinPool.submit(() -&gt; {<br>            // Task implementation goes here<br>        });<br><br>        // Get the parallelism level of the ForkJoinPool<br>        int parallelismLevel = forkJoinPool.getParallelism();<br>        System.out.println(&quot;Parallelism level: &quot; + parallelismLevel);<br><br>        // Set the parallelism level of the ForkJoinPool to 2<br>        forkJoinPool.setParallelism(2);<br>        parallelismLevel = forkJoinPool.getParallelism();<br>        System.out.println(&quot;New parallelism level: &quot; + parallelismLevel);<br><br>        // Get the task queue of the ForkJoinPool<br>        ForkJoinPool.ForkJoinWorkerThreadFactory threadFactory = forkJoinPool.getFactory();<br>        ForkJoinPool.ForkJoinWorkerThread workerThread = threadFactory.newThread(forkJoinPool);<br>        ForkJoinPool.WorkQueue queue = workerThread.workQueue;<br>        System.out.println(&quot;Task queue size: &quot; + queue.getQueuedTaskCount());<br>    }<br>}</pre><p>There are other ways to implement the ForkJoin pool in Java, such as:</p><ol><li>Using the ForkJoinTask interface: This interface represents a task that can be executed asynchronously in the ForkJoin pool. You can create a class that implements this interface and override the compute() method to define the task that needs to be executed.</li><li>Using the RecursiveTask and RecursiveAction classes: These classes extend the ForkJoinTask class and provide additional methods to define tasks that need to be executed recursively. RecursiveTask returns a result, while RecursiveAction does not.</li><li>Using the ManagedBlocker interface: This interface provides a way to block the current thread until a task is completed. It can be used to implement non-ForkJoin tasks that need to be executed in the ForkJoin pool.</li></ol><pre>import java.util.concurrent.*;<br><br>//Using ForkJoinTask<br>public class MyTask extends RecursiveAction {<br>    private int start, end;<br><br>    public MyTask(int start, int end) {<br>        this.start = start;<br>        this.end = end;<br>    }<br><br>    protected void compute() {<br>        if ((end - start) &lt; 100) {<br>            for (int i = start; i &lt; end; i++) {<br>                // Perform some operation<br>            }<br>        } else {<br>            int mid = (start + end) / 2;<br>            invokeAll(new MyTask(start, mid), new MyTask(mid, end));<br>        }<br>    }<br><br>    public static void main(String[] args) {<br>        ForkJoinPool pool = new ForkJoinPool();<br>        MyTask task = new MyTask(0, 1000);<br>        pool.invoke(task);<br>    }<br>}<br><br>//Using RecursiveTask<br>public class MyTask extends RecursiveTask&lt;Integer&gt; {<br>    private int start, end;<br><br>    public MyTask(int start, int end) {<br>        this.start = start;<br>        this.end = end;<br>    }<br><br>    protected Integer compute() {<br>        if ((end - start) &lt; 100) {<br>            int sum = 0;<br>            for (int i = start; i &lt; end; i++) {<br>                sum += i;<br>            }<br>            return sum;<br>        } else {<br>            int mid = (start + end) / 2;<br>            MyTask task1 = new MyTask(start, mid);<br>            MyTask task2 = new MyTask(mid, end);<br>            task1.fork();<br>            int result2 = task2.compute();<br>            int result1 = task1.join();<br>            return result1 + result2;<br>        }<br>    }<br><br>    public static void main(String[] args) {<br>        ForkJoinPool pool = new ForkJoinPool();<br>        MyTask task = new MyTask(0, 1000);<br>        int result = pool.invoke(task);<br>        System.out.println(result);<br>    }<br>}<br><br>//Using RecursiveAction and custom ForkJoinWorkerThreadFactory<br>public class MyTask extends RecursiveAction {<br>    private int start, end;<br><br>    public MyTask(int start, int end) {<br>        this.start = start;<br>        this.end = end;<br>    }<br><br>    protected void compute() {<br>        if ((end - start) &lt; 100) {<br>            for (int i = start; i &lt; end; i++) {<br>                // Perform some operation<br>            }<br>        } else {<br>            int mid = (start + end) / 2;<br>            invokeAll(new MyTask(start, mid), new MyTask(mid, end));<br>        }<br>    }<br><br>    public static void main(String[] args) {<br>        ForkJoinWorkerThreadFactory factory = new ForkJoinWorkerThreadFactory() {<br>            public ForkJoinWorkerThread newThread(ForkJoinPool pool) {<br>                return new MyWorkerThread(pool);<br>            }<br>        };<br>        ForkJoinPool pool = new ForkJoinPool(4, factory, null, false);<br>        MyTask task = new MyTask(0, 1000);<br>        pool.invoke(task);<br>    }<br><br>    private static class MyWorkerThread extends ForkJoinWorkerThread {<br>        protected MyWorkerThread(ForkJoinPool pool) {<br>            super(pool);<br>        }<br>    }<br>}</pre><p>6. CompletableFuture: CompletableFuture uses the same executor service as the ForkJoinPool. You can use a custom executor service with a bounded blocking queue to limit the number of tasks that can be submitted to the CompletableFuture. Below is the example for bounded and unbounded implementation.</p><pre>import java.util.concurrent.*;<br><br>//Bounded queue<br>public class BoundedCompletableFutureExample {<br>    private static final int THREAD_POOL_SIZE = 4;<br>    private static final int QUEUE_SIZE = 10;<br>    private static final ExecutorService executor = new ThreadPoolExecutor(<br>            THREAD_POOL_SIZE, THREAD_POOL_SIZE, 0L, TimeUnit.MILLISECONDS,<br>            new ArrayBlockingQueue&lt;&gt;(QUEUE_SIZE), new ThreadPoolExecutor.CallerRunsPolicy());<br><br>    public static void main(String[] args) {<br>        CompletableFuture&lt;String&gt; future = CompletableFuture.supplyAsync(() -&gt; {<br>            // Some long-running operation<br>            return &quot;Hello&quot;;<br>        }, executor).thenApplyAsync(result -&gt; {<br>            // Some other long-running operation<br>            return result + &quot; World!&quot;;<br>        }, executor);<br><br>        String result = null;<br>        try {<br>            result = future.get();<br>        } catch (InterruptedException | ExecutionException e) {<br>            e.printStackTrace();<br>        }<br><br>        System.out.println(result);<br>        executor.shutdown();<br>    }<br>}<br><br>//Unbounded queue<br>public class UnboundedCompletableFutureExample {<br>    private static final int THREAD_POOL_SIZE = 4;<br>    private static final ExecutorService executor = Executors.newFixedThreadPool(THREAD_POOL_SIZE);<br><br>    public static void main(String[] args) {<br>        CompletableFuture&lt;String&gt; future = CompletableFuture.supplyAsync(() -&gt; {<br>            // Some long-running operation<br>            return &quot;Hello&quot;;<br>        }, executor).thenApplyAsync(result -&gt; {<br>            // Some other long-running operation<br>            return result + &quot; World!&quot;;<br>        }, executor);<br><br>        String result = null;<br>        try {<br>            result = future.get();<br>        } catch (InterruptedException | ExecutionException e) {<br>            e.printStackTrace();<br>        }<br><br>        System.out.println(result);<br>        executor.shutdown();<br>    }<br>}</pre><p>When to use a bounded queue and when to use an unbounded queue depends on the specific requirements of your application. If memory usage is a concern, a bounded queue can help to limit the amount of memory used by your program. However, if you need to submit an unlimited number of tasks to the executor, an unbounded queue may be a better option.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=33d7e0ff4622" width="1" height="1" alt=""><hr><p><a href="https://medium.com/excited-developers/java-multithreading-all-you-need-to-know-33d7e0ff4622">Java Multithreading — All you need to know</a> was originally published in <a href="https://medium.com/excited-developers">Excited Developers</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Meteor App Deployment]]></title>
            <link>https://medium.com/excited-developers/meteor-app-deployment-d406977d5eb3?source=rss----1fdbd0a55dc8---4</link>
            <guid isPermaLink="false">https://medium.com/p/d406977d5eb3</guid>
            <category><![CDATA[meteor]]></category>
            <category><![CDATA[deployment]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[Ashish]]></dc:creator>
            <pubDate>Mon, 13 May 2019 19:30:57 GMT</pubDate>
            <atom:updated>2018-07-06T08:42:20.848Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>Written By <a href="https://medium.com/u/f38880efbba8">Ashish Pandey</a> and <a href="https://medium.com/u/405ecd2301d7">Arshpreet Wadehra</a></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/980/1*KcqbAwqqfdrlwAgptYRJsA.png" /><figcaption>Image Source <a href="https://hackernoon.com/meteor-cms-website-tutorial-2e8da489f92f">Hackernoon</a></figcaption></figure><p>Most of the web developers have uploaded static websites before. The process isn’t too tedious, just get a domain and move the files from your computer to the server machine or use Github and WooF! Website.<br>But Meteor is a different beast and most of the online tutorial wont tell how to host it. Although it isn’t a big deal as you have the option of using <a href="http://meteor-up.com/">MUP</a>, but what will you do if your machine doesn’t supports Docker installation or maybe due to some other issues you can’t use MUP. This article will talk about meteor app deployment manually (i.e without using any third party library).</p><p>(P.S This deployment process is for Ubuntu)</p><ul><li>Login to your server using ssh</li><li>Install node</li></ul><pre>sudo apt-get install nodejs <br>node -v<br>npm -v</pre><ul><li>Install pm2 or forever npm package type</li></ul><pre>sudo npm install pm2 -g<br>sudo npm install forever -g</pre><ul><li>Setup MongoDB(&gt;v3.0) if not installed (type mongo)</li></ul><p><a href="https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/">Install MongoDB on Ubuntu</a></p><pre>mongod --version (P.S. make sure the version is &gt; 3.0)<br>sudo systemctl start mongod<br>mongo<br>Create db using &quot;use &lt;db_name&gt;&quot; like use myMeteorApp</pre><pre>Now create user for db access using<br>db.createUser({user:&quot;test&quot;,pwd:&quot;test&quot;,roles:[&quot;readWrite&quot;]})<br></pre><ul><li>Press Enter to create user user and pwd is in plain text</li><li>After that you need to enable authentication in MongoDB for that exit mongo shell by ctrl+c</li><li>Go to /etc/mongod.conf</li></ul><pre><br>Find #security:</pre><pre>change to </pre><pre>security:<br> authorization: enabled</pre><pre>systemctl restart mongod</pre><ul><li>After successfully setup Mongo. Our Server is almost setup.</li><li>Now go to your meteor app project. Open project in command prompt or terminal.</li><li>If you are pulling it from version control make sure you do npm install in this process. I mean all your npm dependencies must be present in node modules folder.</li><li>Type meteor build — sever-only ./</li><li>It will build your project for production use and compress your build in same directory &lt;project_name&gt;.tar.gz</li><li>Extract your compresses build using tar xzf &lt;project_name&gt;.tar.gz</li><li>It will give you bundle folder in same directory</li><li>Now cd bundle/programs/server</li><li>run npm install — production</li><li>Now go back to bundle cd ../../</li><li>Then we need to export or set Environment variables</li></ul><pre>sudo systemctl start mongod<br>export MONGO_URL=&#39;mongodb://localhost/&lt;dbname&gt;&#39; (i.e myMeteorApp)<br>export ROOT_URL=&#39;http(s)://something&#39; (give your IP if you don&#39;t have a domain) <br>export PORT= 3000 (as per your convenience) </pre><ul><li>After setup Environment variable. Go to bundle directory and run<br>pm2 start — name “UID” main.js</li><li>It will start your server at background you can browse your app &lt;your_ip&gt;:3000 or test via curl localhost:3000</li><li>Nginx setup</li></ul><pre>sudo systemctl start mongod<br>sudo apt-get install nginx<br>vim /etc/nginx/nginx.conf</pre><pre>Go down you will find http block &amp; inside that block paste below</pre><pre>server {<br> listen 80;</pre><pre> server_name domainName.com www.domainName.com;</pre><pre> location / {</pre><pre> proxy_pass http://127.0.0.1:3000;</pre><pre> proxy_set_header Upgrade $http_upgrade;</pre><pre> proxy_set_header Connection &quot;upgrade&quot;;</pre><pre> proxy_set_header X-Real-IP $remote_addr;</pre><pre> proxy_http_version 1.1;</pre><pre> proxy_set_header Host $host;</pre><pre> proxy_connect_timeout       300;</pre><pre> proxy_send_timeout          300;</pre><pre> proxy_read_timeout          300;</pre><pre> }<br>}</pre><pre>(Change domainName to your domain and port number according to your settings. Save the file. Restart nginx <strong>(systemctl restart nginx)</strong>)</pre><p>This is my first medium post so please give your suggestions on how to improve it and correct me if I am wrong anywhere.</p><p><em>Cheers!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d406977d5eb3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/excited-developers/meteor-app-deployment-d406977d5eb3">Meteor App Deployment</a> was originally published in <a href="https://medium.com/excited-developers">Excited Developers</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[File Upload with React & Flask]]></title>
            <link>https://medium.com/excited-developers/file-upload-with-react-flask-e115e6f2bf99?source=rss----1fdbd0a55dc8---4</link>
            <guid isPermaLink="false">https://medium.com/p/e115e6f2bf99</guid>
            <category><![CDATA[file-upload]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[flask]]></category>
            <dc:creator><![CDATA[Ashish]]></dc:creator>
            <pubDate>Mon, 13 May 2019 19:30:29 GMT</pubDate>
            <atom:updated>2018-08-24T10:09:10.975Z</atom:updated>
            <content:encoded><![CDATA[<p>Written by <a href="https://medium.com/u/f38880efbba8">Ashish Pandey</a> and <a href="https://medium.com/u/405ecd2301d7">Arshpreet Wadehra</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KCfgsQe9gfcSy87SQfnHMg.jpeg" /><figcaption>Pic credits (<a href="https://www.youtube.com/watch?v=7JnWfDczo-8">Coding Tech</a>)</figcaption></figure><p>This is will be a very short article on File Upload with React and Flask.</p><p>Client : React Js, and for HTTP Request we will use <a href="https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API">Fetch API</a></p><p><strong>Setting Up the Frontend Environment</strong></p><pre>npm create-react-app frontend<br>cd fileUpload<br>npm start</pre><p>In /fileUpload/src/<strong>index.js</strong>:</p><p>We will simply render the main <strong>&lt;App/&gt; </strong>component.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6f3bf5d39b12ad129ec2bd64711efebf/href">https://medium.com/media/6f3bf5d39b12ad129ec2bd64711efebf/href</a></iframe><p>In /fileUpload/src/<strong>App.js:</strong></p><p>This is the entry component that has the title and the <strong>&lt;Main/&gt; </strong>component.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/141d66dde7d042f0cd739f28efbb1fa8/href">https://medium.com/media/141d66dde7d042f0cd739f28efbb1fa8/href</a></iframe><p>In /fileUpload/src/components/<strong>Main.jsx:</strong></p><p>The following component has a form with <strong>file upload input</strong> and <strong>file name input</strong>. Upon submitting, the handleUploadImage function will be called. The function will alter state’s imageURL<strong> </strong>of uploaded image which is used as the <strong>href </strong>property in image tag on the bottom.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/09d744803748e3e158e6a37be1c2ea6c/href">https://medium.com/media/09d744803748e3e158e6a37be1c2ea6c/href</a></iframe><p><strong>Setting Up Backend</strong></p><p>Backend: Flask (I assume that you have python and flask install. If not Follow this <a href="http://flask.pocoo.org/docs/1.0/installation/">Flask Installation</a>).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9f5724589dc14405a8c0fafb6938df28/href">https://medium.com/media/9f5724589dc14405a8c0fafb6938df28/href</a></iframe><p>Use CORS for local development for production use Nginx and remove the last line. If you need more info about CORS and why are we using it then check this article <a href="https://www.maxcdn.com/one/visual-glossary/cors/">CORS in detail</a> and <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS">CORS MDN</a>. If you want to share data between across two functions we need to use sessions in python. You can avoid the session (line 22) if you don’t need it. Flask is a bit particular about what all you can return. Kindly check the official documentation for that.</p><p>VOILA..!! You are good to go.</p><p>Happy coding and experimenting. Thanks</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e115e6f2bf99" width="1" height="1" alt=""><hr><p><a href="https://medium.com/excited-developers/file-upload-with-react-flask-e115e6f2bf99">File Upload with React &amp; Flask</a> was originally published in <a href="https://medium.com/excited-developers">Excited Developers</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>