Created
September 22, 2017 11:39
-
-
Save arn-ob/a143895bef414397a9d97fafb484f8e1 to your computer and use it in GitHub Desktop.
Defferent Type of Nodejs Server Starting type
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /// 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