Build A Hello World API With Node.js And Express.Js + Postman

Build A Hello World API With Node.js And Express.Js + Postman

·

1 min read

  • Create a new folder and call it hello_world.
 mkdir hello_world
 cd hello_world
  1. In your hello_world folder create a new file called app.js
 touch app.js
  1. Note: you can install node here and

    1. then run cmd with npm init ()

    2. press enter for continue.

    3. enter cmd with npm install express --save

  1. Add content to file app.js

  2.    //Require module
       const express = require('express');
       // Express Initialize
       const app = express();
       const port = 8000;
       app.listen(port,()=> {
       console.log('listen port 8000');
       })
    
       //create api
       app.get('/hello_world', (req,res)=>{
       res.send('Hello World');
       })
    

Test: with browser: http://localhost:8000/hello_world

Check postman

input: http://localhost:3000/hello_world and then click The send button