Parse-server: Unable to listen on port 1337. Port is already in use

Created on 1 Nov 2016  路  14Comments  路  Source: parse-community/parse-server

I just got this message when I start parse server. It was work yesterday, and I did not change anything without change my pc's clock time.
I run parse-server in browser and says "404 page not found" (Not Browser 404 message , parse-server says this msg)
My index.js file is simple,

var express = require('express');
var ParseServer = require('parse-server').ParseServer;
var path = require('path');
var databaseUri = process.env.DATABASE_URI || process.env.MONGODB_URI;
if (!databaseUri) {
console.log('DATABASE_URI not specified, falling back to localhost.');
}
var api = new ParseServer({
databaseURI: databaseUri || 'mongodb://localhost:27017/dev',
cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
appId: process.env.APP_ID || 'myAppId',
clientKey:'CLIENT_KEY',
masterKey: process.env.MASTER_KEY || 'master',
serverURL: process.env.SERVER_URL || 'http://localhost:1337/parse',
liveQuery: {
classNames: ["Posts", "Comments"]
}
});
var app = express();
app.use('/public', express.static(path.join(__dirname, '/public')));
var mountPath = process.env.PARSE_MOUNT || '/parse';
app.use(mountPath, api);
app.get('/', function(req, res) {
res.status(200).send('Parse Server running!');
});
app.get('/test', function(req, res) {
res.sendFile(path.join(__dirname, '/public/test.html'));
});
var port = process.env.PORT || 1337;
var httpServer = require('http').createServer(app);
httpServer.listen(port, function() {
console.log('parse-server-example running on port ' + port + '.');
});
ParseServer.createLiveQueryServer(httpServer);

What's wrong?

Most helpful comment

Assume: Port = 1337

In windows:

A) Find the process
Now go to TaskManager > Performance > Open Resource Monitor
Then find the process id (PID) of the port there.
image
or use this PowerShell command to find PID of port number 1337

Get-Process -Id (Get-NetTCPConnection -LocalPort 1337).OwningProcess

B) Kill the process
Now u can kill the process by the following command:

taskkill /pid 69092 /f

Note: Don't forget that I used example numbers for PID and Port in my example. You should replace them with your numbers.

All 14 comments

It's likely that there's another process serving on port 1337 (perhaps another instance of parse server?)

here's a quick way to check if you're on linux:

lsof -P -iTCP | grep LISTEN

Hi kulshekhar, I use windows. It was work yesterday, today I changed my PC's clock and ran today give this message on cmd. I research any program run in background but I could not. Bu still run parse-server in browser and says "404 page not found" (Not Browser 404 message , parse-server says this msg)

Switch to a Mac? :)

@gateway if you can refrain those kind of comments that would be appreciated.

hi @kulshekhar,

yes, another process serving on port 1337. How to stop that process?

@arpitprod kill -9 process_id - you should see the process id in the second column of the output

@kulshekhar thanks, it's working

@kulshekhar please I don't see any process serving on port 1337, and I still get the same error:

Unable to listen on port 1337. Port is already in use

so how do I free that port?

@EnigmaDX depending on your OS, you'll have to find what's using that port and then stop/kill whatever is using it. If you can't find that, a simple solution might be to change the port to something that's available

  1. Execute
    $ lsof -i :1337
  2. Obtenha o PID. Se 9553 e execute
    $ kill -9 9553
  3. Execute
    $ sails lift

Open terminal and run this command:
$ lsof -i :1337
Output will show PID of process occupying port 1337

Then kill the process with this command
$ kill -9 1234
Sails will now run

Assume: Port = 1337

In windows:

A) Find the process
Now go to TaskManager > Performance > Open Resource Monitor
Then find the process id (PID) of the port there.
image
or use this PowerShell command to find PID of port number 1337

Get-Process -Id (Get-NetTCPConnection -LocalPort 1337).OwningProcess

B) Kill the process
Now u can kill the process by the following command:

taskkill /pid 69092 /f

Note: Don't forget that I used example numbers for PID and Port in my example. You should replace them with your numbers.

or use this PowerShell command to find PID of port number 1337

Get-Process -Id (Get-NetTCPConnection -LocalPort 1337).OwningProcess

B) Kill the process
Now u can kill the process by the following command:

taskkill /pid 69092 /f

following this process, but seems cant see the port 1337 in the list. is there any way to kill the process for 1337?
image

@cassiamanoel Thank you for your post. That worked perfectly.

Was this page helpful?
0 / 5 - 0 ratings