Skip to content

Instantly share code, notes, and snippets.

@arn-ob
Created September 22, 2017 11:39
Show Gist options
  • Select an option

  • Save arn-ob/a143895bef414397a9d97fafb484f8e1 to your computer and use it in GitHub Desktop.

Select an option

Save arn-ob/a143895bef414397a9d97fafb484f8e1 to your computer and use it in GitHub Desktop.
Defferent Type of Nodejs Server Starting type
/// Type 1
var http = require('http');
http.createServer(function(req,res){
// write your Code
}).listen(8000);
/// Type 2
var express = require('express');
var app = express();
app.set('port',process.env.PORT || 5100);
app.listen(app.get('port'),function(){
console.log('Server Running');
});
// type 3
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World!');
}).listen(8080);
//type 4
var http = require('http');
//create a server object:
http.createServer(function (req, res) {
res.write('Hello World!'); //write a response to the client
res.end(); //end the response
}).listen(8080); //the server object listens on port 8080
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment