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 trialHenrik Christensen
Python Web Development Techdegree Student 38,322 Pointsnode.js server
Hi,
When publish your node.js project would you still use the createServer() or is this for developing only?
would this be put online?
const http = require('http');
const hostname = '127.0.0.1';
const port = 3000;
const server = http.createServer((req, res) => {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
Phillip Kerman
Courses Plus Student 285 PointsPhillip Kerman
Courses Plus Student 285 PointsYes--it's not as if "createServer" creates a permanent server though may be intuitive. If this file is named server.js you can first do:
node server.js
Then launch your browser to http://127.0.0.1:3000/ (and see Hello World).As soon as you kill the process (like "ctrl+c" or close the command line), you won't see anything when your browser goes to http://127.0.0.1:3000/.
Is that what you mean?