Thursday, April 6, 2017

Set up local website

Free Hosting on Local Server (Need Broadband):
https://www.noip.com/support/knowledgebase/dynamic-dns-ddns-troubleshooting-guide


Free Hosting on Remote Server (heroku):
https://stackoverflow.com/questions/22550162/how-to-publish-nodejs-website

Node.js Web Module

Open hello-world.js in any preferred text editor and paste in the following content.

const http = require('http');

const hostname = '127.0.0.1';
const port = 3000;

const server = http.createServer((req, res) => {
  res.statusCode = 200;
  res.setHeader('Content-Type', 'text/plain');
  res.end('Hello World!\n');
});

server.listen(port, hostname, () => {
  console.log(`Server running at http://${hostname}:${port}/`);
});


Save the file, go back to the terminal window enter the following command:
$ node hello-world.js
 
An output like this should appear in the terminal to indicate Node.js server is running:
 Server running at http://127.0.0.1:3000/
 
Now, open any preferred web browser and visit http://127.0.0.1:3000.
If the browser displays the string Hello, world!, that indicates the server is working.
Many of the examples in the documentation can be run similarly.
 

No comments:

Post a Comment