0
0
Expressframework~10 mins

Zero-downtime deployment concept in Express - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create an Express server that listens on port 3000.

Express
const express = require('express');
const app = express();
app.get('/', (req, res) => res.send('Hello World!'));
app.listen([1], () => console.log('Server running'));
Drag options to blanks, or click blank then click option'
A3000
B80
C5000
D8080
Attempts:
3 left
💡 Hint
Common Mistakes
Using port 80 without permissions
Using an undefined port variable
2fill in blank
medium

Complete the code to gracefully close the server on shutdown.

Express
const server = app.listen(3000);
process.on('SIGTERM', () => {
  server.[1](() => {
    console.log('Server closed');
  });
});
Drag options to blanks, or click blank then click option'
Aclose
Bstop
Cshutdown
Dend
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-existent methods like stop or shutdown
Calling end which is for streams
3fill in blank
hard

Fix the error in the code to handle new connections during zero-downtime deployment.

Express
const http = require('http');
const server = http.createServer(app);
server.listen(3000);
server.on('connection', (socket) => {
  socket.[1] = false;
});
Drag options to blanks, or click blank then click option'
Aclose
Bdestroy
Cclosed
Ddestroyed
Attempts:
3 left
💡 Hint
Common Mistakes
Using methods instead of properties
Confusing 'close' event with property
4fill in blank
hard

Fill both blanks to track active connections and close them on shutdown.

Express
const connections = new Set();
server.on('connection', (socket) => {
  connections.[1](socket);
  socket.on('close', () => connections.[2](socket));
});
Drag options to blanks, or click blank then click option'
Aadd
Bremove
Cdelete
Dpush
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'push' on a Set
Using 'remove' which is not a Set method
5fill in blank
hard

Fill all three blanks to close all active connections during server shutdown.

Express
process.on('SIGTERM', () => {
  server.[1](() => console.log('Server closed'));
  for (const socket of connections) {
    socket.[2]();
    connections.[3](socket);
  }
});
Drag options to blanks, or click blank then click option'
Aclose
Bdestroy
Cdelete
Dstop
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'stop' which does not exist
Using 'close' on sockets instead of 'destroy'