微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

为什么 'npm start' 不在浏览器中运行项目,Node server.js 在端口 :::3131 ? JavaScript 项目

如何解决为什么 'npm start' 不在浏览器中运行项目,Node server.js 在端口 :::3131 ? JavaScript 项目

我大约一个月前有一个用 JS 编写的项目。从那以后我就没有碰它了。现在我想再次运行该项目。

但是当我输入 Gitbash 'npm start' 时,它不会在浏览器中打开项目。

它停留在:'node server.js' 并且没有更进一步。

昨天我在部署项目的端口 3131 上遇到了问题。我得到了信息,端口很忙。所以我在CMD(windows)中使用'netstat'命令查找所有打开的端口,然后使用'taskkill'终止监听端口3131。

但是即使关闭监听那个端口,'npm start'的效果还是和今天一样。

现在我以前的所有项目都在发生这种情况。所有这些都是在我在线编码学校的在线编码课程中编写的。我大约一个月前完成了它。 它能否以某种方式影响端口 3131 的问题?也许我应该更改端口?

重要信息:项目已部署到 Heroku,但无法在那里工作。但即使在部署到 Heroku 之后,“npm start”也能够在浏览器中运行项目(一个月前)。

顺便说一句,'npm run' 看起来工作正常,它运行所有测试等。


这是我的 package.json:

{
  "name": "fer-07-project","version": "1.0.0","description": "","main": "index.html","scripts": {
    "lint": "eslint --fix --ext .js,.jsx .","init-project": "npm install && npm-run-all init:*","init:dirs": "mkdirp dist src/sass src/css src/vendor src/images src/js","init:files": "touch README.md src/index.html src/sass/style.scss src/js/script.js","init:gitignore": "curl https://raw.githubusercontent.com/github/gitignore/master/Node.gitignore -o .gitignore","init:gitignore:custom": "echo \"dist\" >> .gitignore","test": "npm-run-all test:*","test:html": "globstar nu-html-checker dist/*.html","test:js": "eslint src/js/ --fix","test:scss": "stylelint src/sass/","build": "npm-run-all build:* test","build:clean": "mkdirp dist && rm -r dist && mkdirp dist","build:copy": "copyfiles -a -u 1 -e \"**/sass/**/*\" -e \"**/.gitkeep\" \"src/**/*\" dist","build:sass": "node-sass --output-style compact -o dist/css src/sass","build:autoprefixer": "globstar autoprefixer-cli \"dist/css/*.css\"","build-dev": "npm-run-all build-dev:sass build:autoprefixer","build-dev:sass": "node-sass --output-style expanded --source-map true -o dist/css src/sass","server": "json-server --port 3131 --no-cors --delay 250 --watch dist/db/app.json","watch": "npm-run-all build build-dev -p watch:* server","watch:browsersync": "browser-sync start --server dist --files \"dist/**/*\" --ignore \"dist/db/**/*\"","watch:sassprefixer": "onchange \"src/sass/**/*.scss\" -- npm run build-dev","watch:copy": "onchange -e \"**/sass/**/*\" -e \"**/.gitkeep\" \"src/**/*\" -- copyfiles -a -u 1 {{changed}} dist"
  },"keywords": [],"author": "","license": "ISC","dependencies": {
    "flatpickr": "^4.6.9","json-server": "^0.16.3","rangeslider-pure": "^0.4.11"
  },"devDependencies": {
    "autoprefixer-cli": "^1.0.0","browser-sync": "^2.26.3","copyfiles": "^2.1.0","eslint": "^5.14.1","globstar": "^1.0.0","mkdirp": "^0.5.1","node-sass": "^4.11.0","npm-run-all": "^4.1.5","nu-html-checker": "^0.1.0","onchange": "^5.2.0","stylelint": "^9.10.1","stylelint-scss": "^3.5.4"
  }
}

AND server.js:

/* global require,process */

const jsonServer = require('json-server');
const server = jsonServer.create();
const router = jsonServer.router('dist/db/app.json');
const middlewares = jsonServer.defaults({
  static: 'dist',noCors: true
});
const port = process.env.PORT || 3131;

server.use(middlewares);
server.use(router);

server.listen(port);

使用“YARN START”启动另一个项目时,GITBASH 出现问题

$ yarn start
yarn run v1.22.10
$ npm-run-all -p server:*
$ node server.js
$ webpack-dev-server --mode development --open --hot
events.js:292
      throw er; // Unhandled 'error' event
      ^

Error: listen EADDRINUSE: address already in use :::3131
    at Server.setupListenHandle [as _listen2] (net.js:1318:16)
    at listenInCluster (net.js:1366:12)
    at Server.listen (net.js:1452:7)
    at Function.listen (C:\Users\kpych.LENOVO-KP\OneDrive\Pulpit\Nowy folder (4)\Project-12_Travel_agency\node_modules\express\lib\application.js:618:24)
    at Object.<anonymous> (C:\Users\kpych.LENOVO-KP\OneDrive\Pulpit\Nowy folder (4)\Project-12_Travel_agency\server.js:32:10)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
Emitted 'error' event on Server instance at:
    at emitErrorNT (net.js:1345:8)
    at processticksAndRejections (internal/process/task_queues.js:80:21) {
  code: 'EADDRINUSE',errno: -4091,syscall: 'listen',address: '::',port: 3131
}
error Command Failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
ERROR: "server:api" exited with 1.
error Command Failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Gitbash npm start

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。