<?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: vaibhav singh</title>
    <description>The latest articles on DEV Community by vaibhav singh (@vaibbhav).</description>
    <link>https://dev.to/vaibbhav</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%2F333080%2Fccf8d00e-6f2a-4db6-9f9c-10afb47b2084.png</url>
      <title>DEV Community: vaibhav singh</title>
      <link>https://dev.to/vaibbhav</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/vaibbhav"/>
    <language>en</language>
    <item>
      <title>Send Shell script server output to react client</title>
      <dc:creator>vaibhav singh</dc:creator>
      <pubDate>Mon, 10 Feb 2020 06:19:43 +0000</pubDate>
      <link>https://dev.to/vaibbhav/send-shell-script-server-output-to-react-client-p4e</link>
      <guid>https://dev.to/vaibbhav/send-shell-script-server-output-to-react-client-p4e</guid>
      <description>&lt;p&gt;I'm new in MERN &amp;amp; I have a shell script to upload some data to mongodb,&lt;br&gt;
from nodejs i have to execute shellscript and show it to client side in react like streaming.&lt;/p&gt;

&lt;p&gt;i'm using child process ref. code below and getting the Events output on console.&lt;/p&gt;

&lt;p&gt;But when requesting from React with axios.get() , i'm not getting event wise output, after complete processing, getting the complete output in the response.&lt;/p&gt;

&lt;p&gt;const spawn = require('child_process').spaw;&lt;/p&gt;

&lt;p&gt;const options = {shell: true,detached:true,}&lt;/p&gt;

&lt;p&gt;res.writeHead(200, {'Content-Type': 'text/event-stream','Cache-Control': 'no-cache','Connection': 'keep-alive'});&lt;/p&gt;

&lt;p&gt;var child = spawn(file.sh,[sort_name], options);&lt;/p&gt;

&lt;p&gt;child.stdout.setEncoding('utf8');&lt;/p&gt;

&lt;p&gt;child.stdout.on('data', function (data) {&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;res.write(data);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;});&lt;/p&gt;

&lt;p&gt;child.stderr.setEncoding('utf8');&lt;/p&gt;

&lt;p&gt;child.stderr.on('data', function (data) {&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;res.write(data);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;});&lt;/p&gt;

&lt;p&gt;child.on('close', function (code) {&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log('Full output of script');

res.end();
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;});&lt;/p&gt;

</description>
      <category>npm</category>
      <category>react</category>
      <category>bash</category>
    </item>
  </channel>
</rss>
