Malekbenz

Hi, I'm MalekBenz. I author this blog, I'm FullStack Developer, create courses & love learning, writing, teaching technology. ( Javascript, C#, ASP.NET , NodeJS, SQL Server )

First web application with ExpressJs

Express is a web application framework for nodejs, It is designed for building web applications and APIs. Express is a minimal and flexible Node.js web application framework that provides a robust set of features for web and mobile applications. Express js is great for creating web application and web API.

So… let’s build our first web application with express , HelloExpress application. if you don’t have node js already installed you can Install & run your first application Nodejs.

Install express

Create a HelloExpress directory to hold your application, and make that your working directory

$ mkdir  helloexpress
$ cd helloexpress

create a file ‘app.js’

Now install Express in the HelloExpress directory and save it in the dependencies list. For example:

CMD

$  npm install express

CMD

HelloExpress example

add the following code to app.js file, We use Visual studio code to edit the file:

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

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

    app.listen(3000, function () {
    console.log('App is listening on port 3000!');
    });

vs code

Run the application

Run the application:

    $ node app.js

vs code

The application starts a server and listens on port 3000 for connections. The app responds with “Hello Express!” for requests to the root URL (/) or route. For every other path, it will respond with a 404 Not Found.

load http://localhost:3000/ in a browser to see the output.

vs code

vs code

Our First Express application is working

Comments