Getting started with express

Creating an express app (APIs) under 10 lines of code

Posted by Sesha Sai Srivatsav on November 11, 2017

APIs are super easy to create using express app

Getting started

Create a directory

                       
cd ~
~$ mkdir testExpress
~$ cd testExpress
                       
                

Install Express. The following command will create package json with express on it. Make sure node.js is already installed

                       
~$ node --version
v6.11.3

~$ npm install express --save
                       
                

We will create server

                       
~$ vi server.js
                       
                

Insert the following code in server.js and save the file

                       
var express = require('express');
var app = express();

app.get('/api/test', function (req, res){
	res.send({'message': 'hello'})
})

app.listen(4000);
                       
                

Running the server

                       
~$ node server.js
                       
                

You can test the API either on google chrome or on postman

home page After running the code, this is what you see.