Created
May 18, 2020 19:42
-
-
Save vlazar-/1f719aaf3dd274950ef7d00c0e4caa6c to your computer and use it in GitHub Desktop.
Glitch.com - NodeJS - Express
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
{ | |
"name": "bok-arduino", | |
"version": "0.0.1", | |
"description": "Jednostavna web aplikacija!", | |
"main": "server.js", | |
"scripts": { | |
"start": "node server.js" | |
}, | |
"dependencies": { | |
"express": "^4.17.1" | |
}, | |
"engines": { | |
"node": "12.x" | |
}, | |
"repository": { | |
"url": "https://glitch.com/edit/#!/hello-express" | |
}, | |
"license": "MIT", | |
"keywords": [ | |
"node", | |
"glitch", | |
"express" | |
] | |
} |
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
// server.js | |
// pocetak nodejs aplikacije | |
// ukljucivanje biblioteka pomocu naredbe require | |
// napomena: biblioteke je potrebno dodati putem | |
// package.json-a u sekciji dependencies | |
const express = require("express"); | |
const app = express(); | |
// definiranje lokacije staticki datoteka / resursa | |
//app.use(express.static("public")); | |
// upravlanje rutama aplikacije: | |
//https://expressjs.com/en/starter/basic-routing.html | |
app.get("/", (request, response) => { | |
response.send("Bokic!"); | |
}); | |
app.get("/pozdrav/:ime", (request, response) => { | |
response.send(request.params); | |
}); | |
app.get("/pozdrav/:ime/:prezime", (request, response) => { | |
response.send("Bok " + request.params.ime + " " + request.params.prezime + "! Kako si danas?"); | |
}); | |
app.post("/bok/:ime", (request, response) => { | |
response.send(request.params); | |
}); | |
app.post("/bok/:ime/:prezime", (request, response) => { | |
response.send("Bok " + request.params.ime + " " + request.params.prezime + "! Kako si danas?"); | |
}); | |
// postavljanje porta na kojem radi server | |
const listener = app.listen(process.env.PORT, () => { | |
console.log("Your app is listening on port " + listener.address().port); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment