Posts

Showing posts from October, 2017

Learning MEAN Stack: Express JS - 101

Image
M E AN Express JS is a web framework which makes it easier to build a web server in Node JS. Express helps in writing the NodeJS code cleanly. Installation npm install express - - save Building and running HTML on a web server No need to mention header with Content-Type etc. like done before in nodejs. var express = require ( 'express' ) ; var app = express ( ) ; app . get ( '/' , function ( req , res ) { res . send ( '<html><head></head><body><h1>Hello Sarthak, Welcome to express!</h1></body></html>' ) } ) ; app . listen ( 3000 ) ; run as > nodemon file.js 2.   Using it to build a API. var express = require ( 'express' ) ; var app = express ( ) ; app . get ( '/api' , function ( req , res ) {     res . json ( { firstname : 'Sarthak' , lastname : 'Srivastava' } ) } ) ; app . listen ( 3000 ) ; Send request to   loc