forked from devopstrainingblr/nodejs-application
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
63 lines (44 loc) · 1.61 KB
/
server.js
File metadata and controls
63 lines (44 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
var express = require("express");
const path = require('path');
const cfenv = require('cfenv');
var app = express();
var appEnv = cfenv.getAppEnv();
var port = process.env.port || 3000;
app.get("/getCall", function(req,res){
console.log("GET Method caled");
console.log(__dirname);
res.send("<h2>Welcome to Node JS express app</h2>"+appEnv.url+appEnv.port+port+process.env.LOGNAME+process.env.VCAP_SERVICES);
}).listen(9009);
//app.get("/html", function(req,res){
app.get("/mithuntechnologies", function(req,res){
res.set("Content-Type","text/html");
//res.contentType("html") ;
res.write("<h2>Welcome to Mithun Technologies</h2>");
res.write("<h5>http://mithuntechnologies.co.in http://mithuntechnologies.com/ </h5>");
//must end
res.end();
});
app.get("/jsonData", function(req,res){
res.type('json');
//res.type('application/json');
//res.json({'name': 'Bhaskar Reddy L'});
res.send({'name': 'Bhaskar Reddy'});
});
app.get("/queryparam", function(req,res){
//res.send(req.query);
res.send(req.query.key + ": " + req.query.name);
});
app.get("/status-code-404", function(req, res) {
//set content-type to application/json
//res.sendStatus(404);
res.status(404).send('Sorry, we cannot find that!');
})
app.get("/status-code-500", function(req, res) {
//set content-type to application/json
//res.sendStatus(500);
res.status(500).send('Internal Server Error – custom message');
})
app.get('/redirect', function(req, res) {
//Send status 302
res.redirect('http://google.com');
});