how to run different node app on server different domains


var http = require('http'),
httpProxy = require('http-proxy');

var proxy_web = new httpProxy.createProxyServer({
target: {
host: 'localhost',
port: 8080
}
});

var proxy_api = new httpProxy.createProxyServer({
target: {
host: 'localhost',
port: 8081
}
});

http.createServer(function(req, res) {
if (req.headers.host === 'http://www.domain.com') {
proxy_web.proxyRequest(req, res);
proxy_web.on('error', function(err, req, res) {
if (err) console.log(err);
res.writeHead(500);
res.end('Oops, something went very wrong...');
});
} else if (req.headers.host === 'http://api.domain.com') {
proxy_api.proxyRequest(req, res);
proxy_api.on('error', function(err, req, res) {
if (err) console.log(err);
res.writeHead(500);
res.end('Oops, something went very wrong...');
});
}
}).listen(80);

www.codegrepper.com
www.stackoverflow.com

how to render different pages in nodes


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<!-- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> -->
<link rel="stylesheet" type="text/css" href="/Static/css/spaceGame.css">
<!-- <link rel="stylesheet" href="css/normalize.css"> -->
<link href="https://fonts.googleapis.com/css?family=Raleway:300,400" rel="stylesheet">
<title>{{title}}</title>
</head>
<body>
{{{body}}}

<!-- Footer -->
<script src="https://unpkg.com/vue"></script>
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>

<script type="text/javascript" src="/Static/script/someTest.js"></script>
</body>
</html>

www.codegrepper.com
www.stackoverflow.com

how to push multiple data to different parents in a single request in firebase


var ref = new Firebase("https://<YOUR-FIREBASE-APP>.firebaseio.com");
// Generate a new push ID for the new post
var newPostRef = ref.child("posts").push();
var newPostKey = newPostRef.key();
// Create the data we want to update
var updatedUserData = {};
updatedUserData["user/posts/" + newPostKey] = true;
updatedUserData["posts/" + newPostKey] = {
title: "New Post",
content: "Here is my new post!"
};
// Do a deep-path update
ref.update(updatedUserData, function(error) {
if (error) {
console.log("Error updating data:", error);
}
});

www.codegrepper.com
www.stackoverflow.com