First Steps with Express.js (Node.js) : Starter Setup, Learn Basics for Beginners | Part 2
Tags: node, express, beginners, learning
Published: 2023-05-27 08:38:14

# Intoroduction
Until [Part 1](https://dev.to/koshirok096/first-steps-with-nodejs-expressjs-starter-setup-for-beginners-5734), you created your own Express server! In this article, I’d dig a little deeper Express to learn few more basics.

But to be honest, what I would explain this time are very simple and easy things, so relax, and enjoy your coding practice :)

Let's start with <code>app.get()</code>!

# App.get()
<code>app.get(path, callback)</code> is a function used to associate an <code>HTTP GET request</code> with path. When client send a GET request to the path that you set (**first argument**), callback function (**second argument**) would be excuted.

Here is an example code:

```jsx

import express from "express";

const app = express();

// just added!
app.get("/", (req, res) => {
    res.send("response come from server to path");
})

app.listen(8000, () => {
    console.log("Hey! I listen to port 8000");
})

```

In this code, I set the root path "/" to the first argment and (req, res) for second. **'(req, res) => {}'** is a handler function, which can be used to retrieve request and response objects.

This "req" and "res" are request and response objects - literaly, "req" is about request from client, and "res" is about response from server.

In this example code, syntax returns my message by using 'send' method, when client send a GET request to the path.

The logic is simple as you see - now, you are able to send a request when client access to spefic path on your Express server!

# App.post()
<code>app.post(path, callback)</code> is also a basic, but important function that you should know - It can be used to create **form submissions**, etc.

Function used to associate an <code>HTTP POST request</code> with path. When client send a POST request to the path that you set (**first argument**), callback function (**second argument**) would be excuted. The code structure is similer to above <code>app.get()</code>, but usage is different. Let's see the example code.

```jsx

import express from "express";

const app = express();

// form submissions example
app.post("/submit", (req, res) => {
  const formData = req.body;
  // Process the form data, something code here ...
  res.send("Form submitted");
});

// app.get("/", (req, res) => {
//     res.send("response come from server to path");
// })

app.listen(8000, () => {
    console.log("Hey! I listen to port 8000");

```

This is a simple form submission example.

When an user submits a form on a web page, the common way is that the data to sent as a <code>HTTP POST request</code> to the server. Your app.post() method handles the form submission in order to retrieve the form data, from the client request (req.body) and accordingly process it.

In this example, provided code is not completed yet. But you can add some code inside of <code>app.post()</code> depending on the design or purpose of the project to complete!

# Conclusion
I share just only basic methods in this article, but there some good resources in here Dev.to or Google. If you interested in learning more, let's do it! And I hope it helps your learning :)
See you soon :D