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)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay