У меня есть простой app.js
-
const express = require('express');
const app = express();
//Route
app.get('/', (req, res) => {
res.send('Welcome to custom api');
})
//Listen
app.listen(3000);
Мой пакет. json выглядит так -
{
"name": "custom-api",
"version": "1.0.0",
"description": "\"API to give custom info\"",
"main": "index.js",
"scripts": {
"start": "nodemon app.js"
},
"license": "Apache-2.0",
"dependencies": {
"express": "^4.17.1",
"nodemon": "^2.0.2"
}
}
Я запускаю npm start
и получаю эту ошибку -
> custom-api@1.0.0 start /Users/workspace/server
> nodemon app.js
[nodemon] 2.0.2
[nodemon] to restart at any time, enter `rs`
[nodemon] watching dir(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node app.js`
events.js:187
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE: address already in use :::3000
at Server.setupListenHandle [as _listen2] (net.js:1301:14)
at listenInCluster (net.js:1349:12)
at Server.listen (net.js:1437:7)
at Function.listen (/Users/workspace/server/node_modules/express/lib/application.js:618:24)
at Object.<anonymous> (/Users/workspace/server/app.js:11:5)
at Module._compile (internal/modules/cjs/loader.js:959:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
at Module.load (internal/modules/cjs/loader.js:815:32)
at Function.Module._load (internal/modules/cjs/loader.js:727:14)
at Function.Module.runMain (internal/modules/cjs/loader.js:1047:10)
Emitted 'error' event on Server instance at:
at emitErrorNT (net.js:1328:8)
at processTicksAndRejections (internal/process/task_queues.js:80:21) {
code: 'EADDRINUSE',
errno: 'EADDRINUSE',
syscall: 'listen',
address: '::',
port: 3000
}
[nodemon] app crashed - waiting for file changes before starting...