Getting Started
To get started create a new folder on any directory and call it hello_world.
$ mkdir hello_world
To move to that folder use this command.
$ cd hello_world
In your hello_world folder create a new file called app.js
$ touch app.js
The next step for us to do is to install Node. You can install node here.
We are close to create the app.
After node has been installed then we’ll install express with npm. Node comes with npm so we won’t need to install npm.
npm init
Click the return key repeatedly for every questions asked of you on the command line.
Install Dependencies
npm install express —-save
Setup The App And Create Our First Endpoint
Now let’s get started creating our hello_world
API in the app.js file.
const express = require('express');
const app = express();
Setting Server Port
Add more code in our app.js file.
const port =8000;
Server is listening on port ${port}
app.listen(port,()=> {
console.log();
})
Create API
Let's start writing code for our first API.
app.get('/hello_world', (req, res)=>{
res.send('Hello World');
})
get shows the HTTP GET
First parameter is our API path
Second parameter a callback function
Callback function first request shorthand req
Callback function first response shorthand res
Start Server
Hurrah...! We are just created the server with hello world API next step is pretty easy to start the server run that command.
$ npm start
Check postman
Pretty Easy Congrats you tested it....?
Top comments (0)