User authentication is the core feature of every website and mobile application. Writing authentication the correct and secure way prevents malicious users from accessing sensitive application data.
There are many technologies we can use to enforce secure access to application resources, the most common one is OAuth.
You can read more about OAuth here.
But, for this series, we will build the authentication system from scratch, and make it as simple as possible so it can be further customized and “plugged” with any existing application.
To ensure a smooth and pleasant experience, please make sure before cloning the starter repository to have the following tools installed:
In this section, we will clone the starter project hosted on Github, get familiar with the folder structure, and explore the project dependencies.
- Open a Terminal session and run
git clone https://github.com/2imad/node-js-authentication.git cd node-js-authentication
- Install server dependencies
- Install client dependencies
cd client npm install && cd ..
- Git checkout boilerplate branch
git checkout boilerplate
- Open the project with your favorite text editor, at this stage it should look like this:
|-- node-js-authentication |-- config |-- db |-- mailer |-- middlewares |-- routes |-- .env |-- .gitignore |-- index.js |-- LICENSE |-- package-lock.json |-- package.json |-- README.md |-- client | |-- .gitignore | |-- package-lock.json | |-- package.json | |-- README.md | |-- public | | |-- favicon.ico | | |-- index.html | | |-- logo192.png | | |-- logo512.png | | |-- manifest.json | | |-- robots.txt | |-- src | |-- App.css | |-- App.js | |-- App.test.js | |-- index.css | |-- index.js | |-- logo.svg | |-- reportWebVitals.js | |-- setupTests.js
- Start the development server
npm run server
If you see output like below, it means you are ready to roll :)
[nodemon] 2.0.6 [nodemon] to restart at any time, enter `rs` [nodemon] watching path(s): *.* [nodemon] watching extensions: js,mjs,json [nodemon] starting `node index.js` Listening on 8000
Here is the current dependency list as found on package.json. With each list item, you find a link to the package homepage on npm and a brief introduction.
Important note: .dotenv file should always be included in .gitignore before committing the code.
Finally, some additional resources to help you understand the functionality of each dependency we are using in the project, in case you know any other resources, please do let me know!
In this first part of the series, we talked about authentication with Node.js, cloned the starter repository, and installed the dependencies. Hopefully, you are as excited as I am to get to the next chapter where we will create a MongoDB database and connect it to our project with mongoose, and finally create the signup route.
The next chapter should appear soon, so stay tuned! or signup for my blog and receive it immediately in your mailbox :)