M
M
Millerish2017-06-25 20:43:15
JavaScript
Millerish, 2017-06-25 20:43:15

Node.js: how to stop webserver?

Good evening!
I'm using the gulp-server-livereload plugin !
var server = require('gulp-server-livereload');

gulp.src(pathDir).pipe(server({
   livereload: true,
   directoryListing: true,
   open: true,
   port: 80
}));

How can I stop it from running?
I tried: server.restart(), server.kill(), server.reset()
But errors occur:
Uncaught Error: watch C:\OpenServer\domains\ipcRenderer\node_modules\electron\dist\resources\electron.asar\browser ENOENT
at exports._errnoException (util.js:1022:11)
at FSWatcher.start (fs.js:1316 :19)
at Object.fs.watch (fs.js:1341:11)
at watch (C:\OpenServer\domains\FM\FrontMonkey\node_modules\node-watch\lib\watch.js:221:8)
at C :\OpenServer\domains\FM\FrontMonkey\node_modules\node-watch\lib\watch.js:230:9
at C:\OpenServer\domains\FM\FrontMonkey\node_modules\node-watch\lib\watch.js:41 :14
at Array.forEach (native)
at C:\OpenServer\domains\FM\FrontMonkey\node_modules\node-watch\lib\watch.js:38:18
at ReaddirReq.Req.done (C:\OpenServer\domains\FM\FrontMonkey\node_modules\temp-write\node_modules\graceful-fs\graceful-fs.js:143:5)
at ReaddirReq.done (C:\OpenServer\ domains\FM\FrontMonkey\node_modules\temp-write\node_modules\graceful-fs\graceful-fs.js:90:22)
at ELECTRON_ASAR.js:568:9
at _combinedTickCallback (internal/process/next_tick.js:67:7 )
at process._tickCallback (internal/process/next_tick.js:98:9)
exports._errnoException @ util.js:1022
FSWatcher.start @ fs.js:1316
fs.watch @ fs.js:1341
watch @ C:\ OpenServer\domains\FM\FrontMonkey\node_modules\node-watch\lib\watch.js:221
(anonymous) @ C:\OpenServer\domains\FM\FrontMonkey\node_modules\node-watch\lib\watch.js:230
(anonymous) @ C:\OpenServer\domains\FM\FrontMonkey\node_modules\node-watch\lib\watch.js:41
(anonymous) @ C:\OpenServer\domains\FM\FrontMonkey\node_modules\node-watch\lib \watch.js:38
Req.done @ C:\OpenServer\domains\FM\FrontMonkey\node_modules\temp-write\node_modules\graceful-fs\graceful-fs.js:143
ReaddirReq.done @ C:\OpenServer\domains \FM\FrontMonkey\node_modules\temp-write\node_modules\graceful-fs\graceful-fs.js:90
(anonymous) @ ELECTRON_ASAR.js:568
_combinedTickCallback @ internal/process/next_tick.js:67
_tickCallback @ internal/process/ next_tick.js:98
fs.js:1318 Uncaught Error: watch C:\OpenServer\domains\FM\FrontMonkey\node_modules\electron\dist\resources\electron.asar\browser ENOENT
at exports._errnoException (util.js:1022:11)
at FSWatcher.start (fs.js:1316:19)
at Object.fs.watch (fs.js:1341:11)
at watch (C:\OpenServer\domains \FM\FrontMonkey\node_modules\node-watch\lib\watch.js:221:8)
at C:\OpenServer\domains\FM\FrontMonkey\node_modules\node-watch\lib\watch.js:230:9
at C :\OpenServer\domains\FM\FrontMonkey\node_modules\node-watch\lib\watch.js:41:14
at Array.forEach (native)
at C:\OpenServer\domains\FM\FrontMonkey\node_modules\node-watch\ lib\watch.js:38:18
at ReaddirReq.Req.done (C:\OpenServer\domains\FM\FrontMonkey\node_modules\temp-write\node_modules\graceful-fs\graceful-fs.js:143:5)
at ReaddirReq.done (C:\OpenServer\domains\FM\FrontMonkey\node_modules\temp-write\node_modules\graceful-fs\graceful-fs.js:90:22)
at ELECTRON_ASAR.js:568:9
at _combinedTickCallback (internal /process/next_tick.js:67:7)
at process._tickCallback (internal/process/next_tick.js:98:9)

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
Ilya Shatokhin, 2017-06-26
@Millerish

Judging by the sources, the server stops through the "kill" event.
Try:

const stream = server({
   livereload: true,
   directoryListing: true,
   open: true,
   port: 80
});

gulp.src(pathDir).pipe(stream);

stream.emit('kill');

V
Vitaly, 2017-06-25
@vshvydky

if you can’t find it in the dock, then process.exit() will solve your problem for sure

E
emp1re, 2017-06-26
@emp1re

ps aux | grep node or index.js (any name of the start file)
kill pid -9
If it got lost in the processes.
In general, ctrl + c is enough to exit a non-background process or a command for process managers if, for example, you have pm2.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question