DEV Community

Cover image for WEB applications with Express (beginning)
Collins Mbathi
Collins Mbathi

Posted on

WEB applications with Express (beginning)

Express is a minimal and flexible Node.js web application framework, providing a robust set of features for building web applications.


you first need to create a directory, access it in your shell and install Express using npm by running npm install express --save

Create a file and name it index.js and add the following code which creates an Express server and adds one endpoint to it with the app.get method:

const express = require('express');
const app = express();
app.get('/', (request, response) => {
 response.send('hello World');
app.listen(5000, 'localhost');

Enter fullscreen mode Exit fullscreen mode

To run your command script use the following command in your shell :

node app.js
Enter fullscreen mode Exit fullscreen mode

Your application will accept connections on the port.0. If the hostname argument to app.listen is
omitted, then server will accept connections on the machine's IP address as well as localhost. If port value is 0, the operating system will assign an available port.

Once your script is running, you can test it in a shell to confirm that you get the expected response, "Hello World", from
the server:

curl http://localhost:5000
Hello World

Enter fullscreen mode Exit fullscreen mode

Discussion (2)

gcoleman2001 profile image

Can you do an example where express is used to send and receive soap messages

collins87mbathi profile image
Collins Mbathi Author

Will do that .......