Search code examples
node.jsmacosexpressvue.jslsof

How to kill VueJS application running on localhost:8080 (MacOS)


My environment: MacOS Mojave

I created a VueJS application from their templates using

vue init pwa frontend
? Project name frontend
? Project short name: fewer than 12 characters to not be truncated on homescreens (default: same as name)
? Project description A Vue.js project
? Author [email protected]
? Vue build runtime
? Install vue-router? Yes
? Use ESLint to lint your code? No
? Setup unit tests with Karma + Mocha? No
? Setup e2e tests with Nightwatch? No

yarn
yarn dev

That worked fine. The page ran on localhost:8080 and closed when ctrl-c.

I then built it for production

yarn build

I wrote a quick JS server to launch the contents from the dist/ folder to see what it looks like after building it.

const ora = require('ora')
const chalk = require('chalk');
const express = require('express');
const port = process.env.PORT || 8080;
const app = express();
const spinner = ora(chalk.yellow("Your application is starting..."));
spinner.start();

var delay = ( function() {
    var timer = 0;
    return function(callback, ms) {
        clearTimeout (timer);
        timer = setTimeout(callback, ms);
    };
})();

app.use(express.static(__dirname + "/dist/"));
app.get(/.*/, function(req, res) {
    res.sendFile(__dirname + "/dist/index.html");
});

app.listen(port);

delay(function() {
    app.use(express.static(__dirname + "/dist/"));
    app.get(/.*/, function(req, res) {
        res.sendFile(__dirname + "/dist/index.html");
    });
}, 3000);

spinner.stop();
console.log(chalk.cyan("Your application is running here: ") + ("http://localhost:8080"));

I run the server node server.js

However when I ctrl-c it kills the script however the application is still running on localhost:8080

I have tried sudo lsof -i tcp:8080 and netstat -vanp tcp | grep 8080 and they both returned nothing. Which leaves me with the following question: How do I stop this from listening on port 8080?


Solution

  • If anyone was wondering, I found out the problem. I had to go to chrome://serviceworker-internals and chrome://appcache-internals. I did a search for localhost:8080 and killed those serviceworkers.

    I hope this helps whoever this happens to next!