【发布时间】:2018-10-26 19:26:05
【问题描述】:
我的环境:MacOS Mojave
我使用他们的模板创建了一个 VueJS 应用程序
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 me@myemail.com
? 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
效果很好。该页面在 localhost:8080 上运行并在 ctrl-c 时关闭。
然后我将其构建用于生产
yarn build
我写了一个快速的 JS 服务器来启动 dist/ 文件夹中的内容,看看构建后的样子。
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"));
我运行服务器node server.js
但是,当我 ctrl-c 时,它会杀死脚本,但应用程序仍在 localhost:8080 上运行
我尝试了sudo lsof -i tcp:8080 和netstat -vanp tcp | grep 8080,但它们都没有返回任何内容。这给我留下了以下问题:如何阻止它在端口 8080 上侦听?
【问题讨论】:
-
试试这个命令
lsof -ti:8080 | xargs kill -9 -
不起作用,因为 lsof -ti:8080 不返回任何结果。
-
你如何确定它仍在运行?
-
我要去localhost:8080,应用程序仍在运行。
-
你能试试
npx kill-port 8080吗?
标签: node.js macos express vue.js lsof