Altcademy - a Forbes magazine logo Best Coding Bootcamp 2023

How to allow users to sign in with expressjs and ReactJS sql 2018

Setting the Stage: ExpressJS, ReactJS, and SQL 2018

Before diving into the main subject matter, it's important to understand the key players in this tutorial: ExpressJS, ReactJS, and SQL 2018. ExpressJS is a framework built on top of Node.js that simplifies backend development. ReactJS, on the other hand, is a JavaScript library for building user interfaces. SQL 2018 is the latest version of SQL Server, a relational database management system (RDBMS) developed by Microsoft.

In simpler terms, think of these three as the foundations to a house. ExpressJS represents the foundational structure, ReactJS is the stylish interior, and SQL 2018 is the solid basement where all the essential data is stored.

Creating the Backend with ExpressJS

Our first step is to create the backend of our application using ExpressJS. This is where our users' data will be processed and stored. Imagine it as the engine room of a ship, where all the heavy-duty operations take place.

Here’s a basic ExpressJS server setup:

const express = require('express');
const app = express();
const port = 3000;

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

app.listen(port, () => {
  console.log(`Server running at http://localhost:${port}`);

This code tells our server to respond with "Hello World!" when someone tries to access the homepage ('/') of our application.

Building the Frontend with ReactJS

The next step is building the frontend with ReactJS. This is the part of the application that users directly interact with, like the control room of our ship.

Here's a basic ReactJS component:

import React from 'react';

class SignIn extends React.Component {
  render() {
    return (
        <h1>Sign In</h1>
            <input type="text" name="username" />
            <input type="password" name="password" />
          <input type="submit" value="Submit" />

export default SignIn;

This code creates a Sign In form where users can enter their username and password.

Integrating SQL 2018

Now, let's integrate SQL 2018 to store user data. You can think of SQL 2018 as the ship's logbook where all important information is recorded.

Here's how you might set up a basic connection to a SQL 2018 database:

const sql = require('mssql');

const config = {
  user: 'username',
  password: 'password',
  server: 'localhost',
  database: 'MyDatabase'

sql.connect(config).then(pool => {
  return pool.request().query('select * from mytable')
}).then(result => {
}).catch(err => {

This code establishes a connection to a database named 'MyDatabase' and fetches all records from a table named 'mytable'.

Linking Frontend and Backend

The next step in our voyage is to link the frontend and backend. This is like making sure the control room can communicate with the engine room.

Here's how you might send a POST request from the ReactJS frontend to the ExpressJS backend when the form is submitted:

import React from 'react';
import axios from 'axios';

class SignIn extends React.Component {
  handleSubmit = event => {
    const user = {
    };`http://localhost:3000`, { user })
      .then(res => {

  render() {
    // of the code

export default SignIn;

And here's how you might handle the POST request in the ExpressJS backend:

const express = require('express');
const bodyParser = require('body-parser');
const app = express();
const port = 3000;

app.use(bodyParser.json());'/', (req, res) => {

// of the code

Conclusion: The Voyage's End

We've reached the end of our voyage! Remember, like a ship, your application won't sail on its first day. It takes constant tuning and adjustment to make sure everything works together smoothly.

By now, you should have a basic understanding of how to allow users to sign in with ExpressJS and ReactJS, backed by SQL 2018. As you continue to learn and explore, you'll discover that the possibilities are as vast as the open sea!