DEV Community

Aaric Evans
Aaric Evans

Posted on

how to make node.js and express.js run on the same server?

long story short: just keep the ports different.

for e.g., if nodejs is running on 3000, then make express.js run on 3001

Because they cannot both listen on the same port at the same time. If you try to do this, you will get an error.

you can use the below code

const express = require('express');
const app = express();

app.get('/', (req, res) => {
  res.send('Hello, world!');
});

app.listen(3000);
Enter fullscreen mode Exit fullscreen mode

Once you have both Node.js and Express running on different ports, you can access your application by visiting http://localhost:3000 for the Node.js server and http://localhost:3001 for the Express server.

Top comments (0)