curl -sL https://deb.nodesource.com/setup | sudo bash -
apt-get install nodejs
apt-get install nanocd ~
mkdir web
cd web
npm init
npm install express --savenano index.js
# Remember [CTRL][X] then [Y] to quitnano index.js
# Remember [CTRL][X] then [Y] to quitvar 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.jsres.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
});