curl -sL https://deb.nodesource.com/setup | sudo bash -
apt-get install nodejs
apt-get install nano
cd ~
mkdir web
cd web
npm init
npm install express --save
nano index.js
# Remember [CTRL][X] then [Y] to quit
nano index.js
# Remember [CTRL][X] then [Y] to quit
var express = require("express");
var app = express();
app.get("/", function(req, res) {
res.send("Hello!");
});
app.listen(80, function() {
console.log("Listening on port 80!");
});
Run with `node index.js` and go to your server's IP and look at the output!
mkdir html
cd html
nano index.html
cd ..
nano index.js
res.sendFile("index.html");
app.get("/hello", function(req, res) {
if (req.query.name) {
res.send("Hello There " + req.query.name + "!");
} else {
res.send("Hello!");
}
});
Now run and go to /hello?name=Jeff
app.get("/hello/:name", function(req, res) {
// req.params
});