Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Build a REST API With Express Building API Routes in Express Building the Question Routes

Andrew Young
PLUS
Andrew Young
Courses Plus Student 639 Points

Can we use express with http module?

I'm wondering because that I don't start developing express when I first touch node.js, so I use http.createServer function to listen the port. So I'm wondering we listen to a port (for produtive app we've listen 80 port) with express when building API, than we listen to 80 port again fo static site content using http.createServer function can it work with two application listen to a same port?

Caleb Kleveter
Caleb Kleveter
Treehouse Moderator 37,862 Points

Two applications, or two different modules in an app?

Andrew Young
Andrew Young
Courses Plus Student 639 Points

I meant I have using http.createServer function to listen 80 port and print/write out all input of the code I write to handle site for visitor, and I want to also have a express listening on 80port for making APIs and all the api with be under the /api path. Is it possible?

1 Answer

You could just use different ports, but that sort of defeats the purpose. You'd be better off setting up static routes in Express:
https://expressjs.com/en/starter/static-files.html