Setup node framework | Express

 First step to start with express is to install express in our project.

    > npm install express 

This command will add express dependency into package.json file and download packages from internet.


Let's create a new express server:

const express = require("express");

const app = express();
const PORT = 3000;

app.listen(PORT, function(){
    console.log("Server started on port "+PORT);
});












    Here is an error Cannot GET / becoz we do set the request or response from the server:


app.get("/", function(request, response){
    console.log(request);
});



We can see now all the request parameters in console.

To send the response to the client : 


app.get("/", function(req, res){
    res.send("Hello Express...");
});



Now we can see the output that is a response from the server on / location.

You can also send HTML as a response


app.get("/", function(req, res){
    res.send("<h1>Hello Express</h1>")
});



fgdfgdf



Comments

Popular posts from this blog

calculator app using node express

React for Beginners