const express = require('express');
const { uuid } = require('uuidv4');


const app = express();

app.use(express.json())

const projects = [];

app.post('/projects', (req,res)=>{

 const { title, owner } = req.body;
 
  const project = { id: uuid() , title, owner };
  projects.push(project);

  return res.json(project)
})

app.listen(6690, ()=>{
  console.log('Started!????');
});

当我执行nodemon时:

[nodemon] restarting due to changes...
[nodemon] starting `node src/index.js`
node:events:498
      throw er; // Unhandled 'error' event
      ^

Error: listen EADDRINUSE: address already in use :::6690
    at Server.setupListenHandle [as _listen2] (node:net:1330:16)
    at listenInCluster (node:net:1378:12)
    at Server.listen (node:net:1465:7)
    at Function.listen (C:\Users\Lord\desktop\projetos\bootcamp\backend\node_modules\express\lib\application.js:618:24)
    at Object.<anonymous> (C:\Users\Lord\desktop\projetos\bootcamp\backend\src\index.js:21:5)
    at Module._compile (node:internal/modules/cjs/loader:1103:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1155:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
Emitted 'error' event on Server instance at:
    at emitErrorNT (node:net:1357:8)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  code: 'EADDRINUSE',
  errno: -4091,
  syscall: 'listen',
  address: '::',
  port: 6690
}
[nodemon] app crashed - waiting for file changes before starting...

但如果我再更新一次,效果很好:

[nodemon] restarting due to changes...
[nodemon] starting `node src/index.js`
Started!????

如果我再更新一次,再更新一次...一切都会重演

如果我再更新一次,再更新一次...一切都会重演

推荐答案

从您的日志(log)中,我们想到的第一个问题是,当您的nodemon停止或等待时,它并不正常存在,因此端口已被使用.

Node.js相关问答推荐

如何使用updateMany()和Node.js的方法?

express返回意外的URL

带有apache Couch-db和Nano的推荐引擎:过滤特定用户的视图

未显示NPM版本

模块';"; node :流程&没有导出的成员';dlopen';

使用AWS SDK for JavaScript V3将图像从node.js上传到s3 bucket

如何创建具有不同对象类型的数组类型

密码加密的最佳实践是什么?

在父模式中设置默认值.

$not 的聚合版本是什么?

在路由上使用中间件时,Nodejs Express 应用程序失败

当我try 从本地主机发布新产品时收到错误消息

在系统启动时启动本地 node 服务器

在 React 和 Socket.io 中使用 Effect 钩子重新渲染两次

是Electron 的密码和登录凭据的安全存储吗?

node.js 变量不存在代码块

Web3.js 脚本在监听 CreatedPairs 时退出

解决并行保存到 mongodb

使用 WebSockets 有服务器成本吗?

使用 Mongoose 进行多对多映射