<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Hendra Kusuma</title>
    <description>The latest articles on Forem by Hendra Kusuma (@hendrakusuma).</description>
    <link>https://forem.com/hendrakusuma</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F987257%2F7e34ce71-5095-4a83-9328-f0f596d7fb3a.jpeg</url>
      <title>Forem: Hendra Kusuma</title>
      <link>https://forem.com/hendrakusuma</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/hendrakusuma"/>
    <language>en</language>
    <item>
      <title>Creating routing API with Express JS</title>
      <dc:creator>Hendra Kusuma</dc:creator>
      <pubDate>Sat, 18 Feb 2023 22:43:57 +0000</pubDate>
      <link>https://forem.com/zettasoft/creating-routing-api-with-express-js-2ilh</link>
      <guid>https://forem.com/zettasoft/creating-routing-api-with-express-js-2ilh</guid>
      <description>&lt;p&gt;Hello everyone, back again with me. Now I want to share again about creating routing API with express JS. This article continues the previous article so make sure you have read the previous article. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Background&lt;/strong&gt;&lt;br&gt;
In this case, currently, I'm on learning Javascript backend, I want to give a tutorial about make a routing API using Node JS Express for backend developer for those who all read this article&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Task&lt;/strong&gt;&lt;br&gt;
making a routing in coding&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Getting Started&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;routing has 3 method, it has 'App method', 'chain method', and 'modular method'. I show you in the code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;express = require('express')
app = express()
//this is a 'APP METHOD'
  app.get(`/`, (req, res) =&amp;gt; {
    res.send('Hello World!')
  })

 // /user/create
  app.post('/create', (req, res) =&amp;gt; {
    res.send('Create Order!')
  })

  // /user/update
  app.put('/update', (req, res) =&amp;gt; {
    res.send('Update Order')
  })

app.listen(3000, () =&amp;gt; {
  console.log('server is running on port 3000')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;you can running and check on your browser &lt;code&gt;localhost:3000/&lt;/code&gt;, or &lt;code&gt;localhost:3000/user/create&lt;/code&gt;, or &lt;code&gt;localhost:3000/user/update&lt;/code&gt;. You can check it one by one on Postman. And for Chaining Method, you can see on below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// this is 'CHAINING METHOD'
app.route('/product')
 .get(req, res)) =&amp;gt; {
 res.send('get a route /product')
}
.post(req, res)) =&amp;gt; {
 res.send('post a route /product')
}
.put(req, res)) =&amp;gt; {
 res.send('put a route /product')
}
.delete(req, res)) =&amp;gt; {
 res.send('delete a route  /product')
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The chaining method looks almost the same but for the initial invocation using 'app.route', it remains only to call '.get' 'post', 'put', 'delete'.&lt;/p&gt;

&lt;p&gt;And the next is 'modular method'. In simple terms, this method is to separate the route file javascript, lets say we make new file JS from the main file, let say we name it "mainFile.JS". so the route code is not combined with the main file, this functions to make our files more tidy and structured. let's see in the code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const express = require('express')
const app = express()
const routes = require('router')
const router = express.Router()

// Routing 'MODULAR METHOD'
app.use('/api', (routes(router)

app.listen(8000, () =&amp;gt; {
  console.log('Server is running on port', 8000)
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To configuration for router in express, There we call the default function express module, namely &lt;code&gt;const router = express.Router()&lt;/code&gt;. We can see there how the routing module is called by using &lt;code&gt;app.use&lt;/code&gt; with its link function &lt;code&gt;/api&lt;/code&gt;. the function of 'app.use' we can use any routing, midelware, or plugin external. And then we calling/import the routes variable which is the file routing JS its has been called outside the main file JS by using &lt;code&gt;require&lt;/code&gt;, so we can create a new file for routing example 'routes.js', let's code the contents in routes.js.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;module.exports = function (router) {
  router.get('/', function (req, res) {
    res.send('Routes Modular!')
  })

  router.post(`/create`, function (req, res) {
    res.send('create')
  })

  return router
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;if the routing goes well, it will run as it should and if the application is run it using command &lt;code&gt;node main.js run&lt;/code&gt; can be checked according to the routing link e.g. &lt;code&gt;localhost:3000/user/update/api/create&lt;/code&gt;. If you successfully appear create on the browser page, it means that you have succeeded in using the modular method.&lt;/p&gt;

&lt;p&gt;okay thanks for your read, see you in the next post :)&lt;/p&gt;

&lt;p&gt;Github :&lt;a href="https://github.com/Hendra-Kusuma"&gt;https://github.com/Hendra-Kusuma&lt;/a&gt;&lt;br&gt;
Email : &lt;a href="mailto:hendrakusuma.vegas@gmail.com"&gt;hendrakusuma.vegas@gmail.com&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Create server using Node JS with Framework Express</title>
      <dc:creator>Hendra Kusuma</dc:creator>
      <pubDate>Wed, 21 Dec 2022 07:45:30 +0000</pubDate>
      <link>https://forem.com/zettasoft/create-server-using-node-js-with-framework-express-39d9</link>
      <guid>https://forem.com/zettasoft/create-server-using-node-js-with-framework-express-39d9</guid>
      <description>&lt;p&gt;Hello, come back again with me, this time I want to give you a tutorial on how to create a server using Node JS with the framework Express. this time is different from the previous article. if previously discussed how to create a server natively, now I will explain about creating a server using the Express framework&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Background&lt;/strong&gt;&lt;br&gt;
In this case, currently, I'm on learning Javascript backend, there are 2 ways to native and use the framework Express JS, I want to give a tutorial for those who all read this article&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Task&lt;/strong&gt;&lt;br&gt;
create a server locally with the Javascript language using the framework Express&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Getting Started&lt;/strong&gt;&lt;br&gt;
For the first step, you can use in command line &lt;code&gt;npm init&lt;/code&gt;, and you can input information there about your package or your file. that is a starter pack and will add file package.json and there is store all the information that you have entered. After that, you can add file js, for example, you can add server.js. you can install library express on the command line, the command is &lt;code&gt;npm install express&lt;/code&gt;. We can see the code below&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const express = require('express')

const app = express()

app.get('/', (req, res) =&amp;gt; {
  res.send('Hello Handsome!')
})

app.listen(8000, () =&amp;gt; {
    console.log('Example app listening on port 8000!')
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--AAJ89hsL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rpzjic3ltcix13p4qho8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--AAJ89hsL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rpzjic3ltcix13p4qho8.png" alt="preview on http://localhost:8000/" width="454" height="158"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We can see the improvement in code there is easier to understand and simple for code than using native. You can call the express function using require, and all stored functions on the variable &lt;code&gt;app&lt;/code&gt;.  Now there is to use the method &lt;code&gt;get&lt;/code&gt; you can use: &lt;code&gt;app.get('/', (req, res) =&amp;gt; {&lt;br&gt;
  res.send('Hello Handsome!')&lt;br&gt;
})&lt;/code&gt;&lt;br&gt;
now on framework Express, the method you use is &lt;code&gt;res.send&lt;/code&gt; not res.end.&lt;/p&gt;

&lt;p&gt;you can make routing on Express, I show you the code below :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const express = require('express')

const app = express()

const auth = 'Bearer 1234'

app.get('/', (req, res) =&amp;gt; {
  res.send('Hello Handsome!')
})

app.get('/user', (req, res) =&amp;gt; {
    console.log('req.headers.authorization', req.headers.authorization)
    if (req.headers.authorization === auth) {
        res.send({
            name: 'Hendra Kusuma',
            job : 'Programmer',
            age : 33,
            favorite_food : 'Nasi Goreng'
         })
    }   else {
        res.status(401).send('Unauthorized')
    } 

})

app.listen(8000, () =&amp;gt; {
    console.log('Example app listening on port 8000!')
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;you can see that, routing can be created using the function 'if' and 'else'. If you look at the routing, it is distinguished by the '/' and '/user' signs after the URL address. &lt;/p&gt;

&lt;p&gt;The data type for 'res' can be HTML or JSON text. exemplified in the '/user' routing it is in the form of JSON, and for other than status code 200, for example, 401 the contents are in the form of an unauthorized text file. I have added coding to check authorization, to read the headers it needs a Postman application, and I have tried to check how it looks when using authorize bearer Token in the postman application. The display can be seen below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--RhIaOds7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/17oafexrshm1j0f1186x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--RhIaOds7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/17oafexrshm1j0f1186x.png" alt="Preview Postman" width="880" height="552"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;okay, that is the simple ways to make server using Express. thanks for your read, see you in the next post :)&lt;/p&gt;

&lt;p&gt;Email : &lt;a href="mailto:hendrakusuma.vegas@gmail.com"&gt;hendrakusuma.vegas@gmail.com&lt;/a&gt;&lt;br&gt;
Source code : &lt;a href="https://github.com/Hendra-Kusuma/Express-Web"&gt;https://github.com/Hendra-Kusuma/Express-Web&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>Create server using Node JS Native Javascript</title>
      <dc:creator>Hendra Kusuma</dc:creator>
      <pubDate>Fri, 16 Dec 2022 04:03:26 +0000</pubDate>
      <link>https://forem.com/zettasoft/create-server-using-node-js-native-javascript-45k7</link>
      <guid>https://forem.com/zettasoft/create-server-using-node-js-native-javascript-45k7</guid>
      <description>&lt;p&gt;Hello, in this post I want to share with you how to create a simple server on your local host.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Background&lt;/strong&gt;&lt;br&gt;
In this case, I'm on learning Javascript backend, there are 2 ways to native and use the framework Ekspress JS, I want to give a tutorial for those who all read this article&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Task&lt;/strong&gt;&lt;br&gt;
create a server locally with the Javascript language&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Getting Started&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;the first step is you need to make an index.js file and call a module/library Https, the code is just like this &lt;code&gt;const http = require('http')&lt;/code&gt;. this method "require" is calling the HTTP method, the "http is a built-in library in Node JS, so you can only call it on your code. &lt;/p&gt;

&lt;p&gt;then to create a server, the code can be like below&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const http = require('http')

const listener = http.createServer((req, res) =&amp;gt; {
    console.log('req.headers.autorization', req.headers.authorization)
    if (req.url === '/user'){
        res.writeHead(200, {'Content-Type': 'application/json'})
        res.end(JSON.stringify({ name : 'John Doe'}))
    }   else {
        res.writeHead(200)
        res.end('Hello World')
    }

})

listener.listen(8000, 'localhost', () =&amp;gt; {
    console.log('Server is listening on port 8000')
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;the method &lt;code&gt;http.createServer&lt;/code&gt; have the callback parameter req and res, as we know req for a request and res for a response. if we want to make a routing in native node JS we can use &lt;code&gt;if (req.url === '/user')&lt;/code&gt;. it is just an example for /user. if we run it will show &lt;code&gt;name: 'John Doe'&lt;/code&gt; and for "else" or other it will show &lt;code&gt;'Hello World'&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;And we can run in terminal command bash with &lt;code&gt;node index.js&lt;/code&gt;. And then notice will prompt on the terminal "Server is listening on port 8000". We can see on our browser on locallost:8000. We have already succeeded to build a server with native node JS, the preview is below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy5bw7ny8pk45bfxqbctv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy5bw7ny8pk45bfxqbctv.png" alt="preview localhost:8000 on browser"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwwf13v6e9sfcxebypzzf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwwf13v6e9sfcxebypzzf.png" alt="preview localhost:8000/user on browser"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;okay thanks for your read, see you in the next post :)&lt;/p&gt;

&lt;p&gt;Github :&lt;a href="https://github.com/Hendra-Kusuma" rel="noopener noreferrer"&gt;https://github.com/Hendra-Kusuma&lt;/a&gt;&lt;br&gt;
Email : &lt;a href="mailto:hendrakusuma.vegas@gmail.com"&gt;hendrakusuma.vegas@gmail.com&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>beginners</category>
      <category>node</category>
      <category>javascript</category>
    </item>
    <item>
      <title>How to make a Calendar using Python Tkinter</title>
      <dc:creator>Hendra Kusuma</dc:creator>
      <pubDate>Mon, 12 Dec 2022 08:52:48 +0000</pubDate>
      <link>https://forem.com/zettasoft/how-to-make-a-calendar-using-python-tkinter-4ijj</link>
      <guid>https://forem.com/zettasoft/how-to-make-a-calendar-using-python-tkinter-4ijj</guid>
      <description>&lt;p&gt;Hello, I want to teach you to make a calendar with Python language programming, &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Background&lt;/strong&gt;&lt;br&gt;
In my case I want to make a simple GUI for an app that need a calendar to see and maintain that app. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Getting started&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To do that we need a library python which is name is "Tkinter". lets we do it first you must import &lt;code&gt;from tkinter import *&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;as you know, Tkinter is the built-in library in python, so you don't need to install them, you can just call them in command import as above. and the next step is basic standard code to run Tkinter, you can follow this code to run Tkinter.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from tkinter import *

window = Tk()
window.title("Welcome to Helloworld app") #this for your title

width = 400 #this is for the width size of the window
height = 400 #this is for the height size of the window
x = 500 #this is the distance your window with the border screen of your laptop/PC from up and down
y = 200 #this is the distance between your window with your border screen of the laptop/PC from left and right

window.geometry(f"{width}x{height}+{x}+{y}") #this for size window

window.mainloop() #this to run your tkinter
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;this is the first step you can run your Tkinter, it opened as you run it, but not done yet because it's empty in your window. We can fill it with code to make a calendar. now the next step you can add import &lt;code&gt;from tkcalendar import *&lt;/code&gt; or if you don't have this you can install it with this command &lt;code&gt;pip install tkcalendar&lt;/code&gt; on your terminal.&lt;/p&gt;

&lt;p&gt;And then, we can input the code like this,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from tkinter import *
from tkcalendar import *

window = Tk()
window.title("Welcome to Helloworld app")
width = 400
height = 400
x = 500
y = 200

window.geometry(f"{width}x{height}+{x}+{y}")

def date_picker():
    date = myCal.get_date()
    date_label = Label(window, text="This date is" + date)
    date_label.grid(row=7, column=1, ipadx=10, ipady=10, sticky="wesn", pady=10)

myCal = Calendar(window, selectmode="day", date_pattern="dd/mm/yyyy", )
myCal.grid(row=0, column=0, columnspan=3, rowspan=5, sticky="wesn", pady=50)
OpenCal = Button(window, text="Select Date", command=date_picker)
OpenCal.grid(row=6, column=1, ipadx=10, ipady=10, sticky="wesn", pady=10)

window.mainloop()

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I add widget button and function &lt;code&gt;date_picker&lt;/code&gt;&lt;br&gt;
to get data of date in calendar, so we can see the result on below&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwbg5d9m05fm8lxw592qu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwbg5d9m05fm8lxw592qu.png" alt="the result of calendar with button widget" width="502" height="539"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;we can see if we chose date on calendar and click the button, we can get the date on label column.&lt;/p&gt;

&lt;p&gt;okay thanks for your read, see you in the next post :)&lt;/p&gt;

&lt;p&gt;Github :&lt;a href="https://github.com/Hendra-Kusuma" rel="noopener noreferrer"&gt;https://github.com/Hendra-Kusuma&lt;/a&gt;&lt;br&gt;
Email : &lt;a href="mailto:hendrakusuma.vegas@gmail.com"&gt;hendrakusuma.vegas@gmail.com&lt;/a&gt;&lt;/p&gt;

</description>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
