DEV Community

loading...

Head Start to Express

shiv008 profile image Shivam Updated on ・2 min read

Getting started with Express

what the heck Express is ??

*So the answer is Express.js or Express is backend web application framework for node.js so that you can go and create your backend logic there for your web app or mobile application such as API *

Before creating your first API using express let's know few things that we are going to cover in this post in this post we will learn to create API express.js using replit that provides you node environment so you can use it.
I learned Express this way and found it very simplest so anyone to pick and can learn it just like that it's my personal opinion might you feel difficult so here it is

let's create your first API using express in few steps

*open replit and create an account over there.
Now you can see there an option for creating repl
*select for node.js and create your repl.
now you can see you have an environment in which you have files section editor and console over there

*now as you can see at the top of your index.js where something is written as not sure

Not sure what to do try some examples.

or put this code there

const express = require('express');

const app = express();

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

app.listen(3000, () => {
  console.log('server started');
});
Enter fullscreen mode Exit fullscreen mode

*click on examples and select for Server (Express) and run it so repl will install dependency for your express server and Voila! your express server is started listening on port 3000

so here you are add express as a dependency when you calling express() like this is creating an instance of express.
When you doing app.get it takes first on an argument the route in this case route is root '/' and second is call back from where we are returning an HTML with the response as res.send('hello Express app!').
If you don't want to return data in JSON format you can use res.json({text:'Hello Express app})' so it will return data in JSON format.
also, you can create multiple routes using app.get

  • On your right side of the screen you can see a browser screen in running upside of your console you can copy that URL of your sever and put it where ever you want and because you are using repl your express server is live over the wire.

Discussion (0)

Forem Open with the Forem app