to setup our basic server we can write the following code
const express = require('express');
const app = express();
app.get('/', (req, res) => {
res.send('Server is running...');
});
app.listen(18, () => console.log('Server is up at 18!'));
This will start a server and will display server is running for /
It won’t return any additional data as a response. For that, you have to set responses for particular routes. For example, if you want to visit the route /imran and send response data as “he is my master” in your browser you have to specify the route and set response data. Something like this
app.get('/imran', (req, res) => {
res.send('he is my master');
});
Working? Feels great right?
I had the same feeling when it worked for me for the first time. Logging out now as I have some urgent deliverables in my office. Will get back soon. Chao!