         (fn [buffer]
           (write (.toString buffer)))]
 
-    (.on socket "connect"
-      (fn [err]
-        (if err
-          (do (println "shadow-cljs - socket connect failed")
-              (js/process.exit 1))
+    (write (str "(shadow.cljs.devtools.cli/from-remote " (pr-str exit-token) " " (pr-str error-token) " " (pr-str (into [] args)) ")\n"))
 
-          (do (write (str "(shadow.cljs.devtools.cli/from-remote " (pr-str exit-token) " " (pr-str error-token) " " (pr-str (into [] args)) ")\n"))
-
-              (js/process.stdin.on "data" stdin-read)
-              (js/process.stdin.on "close" stop!)
-              ))))
+    (js/process.stdin.on "data" stdin-read)
+    (js/process.stdin.on "close" stop!)
 
     (.on socket "data"
       (fn [data]

  (:require [cljs.reader :as reader]
            ["readline" :as rl]
            ["net" :as node-net]
            [shadow.cljs.npm.util :as util]
            [clojure.string :as str]))


          (.end socket)
          (println))]

    (println "shadow-cljs - connected to server")

    ;; FIXME: this is an ugly hack that will be removed soon
    ;; its just a quick way to interact with the server without a proper API protocol
    (write (str "(shadow.cljs.devtools.cli/from-remote " (pr-str exit-token) " " (pr-str error-token) " " (pr-str (into [] args)) ")\n"))

    (.on rl "line"
      (fn [line]
        (write (str line "\n"))))

    ;; CTRL+D closes the rl
    (.on rl "close"
      (fn []
        (stop!)))

    (.on socket "data"
      (fn [data]
