Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update index.js #56

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 25 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
const express = require('express')
const app = express()
app.all('/', (req, res) => {
console.log("Just got a request!")
res.send('Yo!')
})
app.listen(process.env.PORT || 3000)
const http = require('http');
const url = require('url');

const server = http.createServer((req, res) => {

req.query = url.parse(req.url, true).query;
const radius = req.query.radius;

if (radius === undefined) {
res.statusCode = 400;
res.setHeader('Content-Type', 'text/plain');
res.end('Nama: Vincent Sompie\nNIM: 210211060120\n\nError: Silahkan memasukkan parameter radius pada request query.\n');
} else {
const area = Math.PI * radius ** 2;
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end(`Nama: Vincent Sompie\nNIM: 210211060120\n\nLuas lingkaran dengan jari-jari ${radius} adalah ${area}.\n`);
}
});

const PORT = 3000

server.listen(PORT, () => {
console.log(`Server up and running at port ${PORT}`);
});