This is a dummy project that helps you to start your frontend project and setup a basic authentication flow.
- NodeJs installed
v12.x.x
or higher. - Yarn installed -> use
npm install --global yarn
if you want to setup yarn
Thats it for the requirements.
Setting up project is relatively easy if you have Node.js
installed in your pc.
- Clone the repo or download the repo from https://github.com/Sniper-Code/AuthJs
- Open terminal pointing to cloned directory and follow the Instructions section.
- Internet connection to download required packages.
- Node.js version 12.x.x or higher. (v14+ recommended)
- VisualStudio Code (VsCode) latest version.
I assume that the user has installed Node.js version 12.x.x or higher. (v14+ recommended) and the user has internet connection to download required packages. The user knows how to install Node.js version 12.x.x or higher if not installed. The user also have basic knowledge of how to use command line and VsCode.
Please use VisualStudio Code(VsCode) to have a better experience exploring files and all the documents of the project. Open the "Readme.md" file in VsCode and use "ctrl+shift+v" command to have a better experience.
To run the project open your command line interface (CLI) and navigate to the current directory and observe whether the node_modules
folder is created. If not then run the following command:
yarn setup
This will install all the required packages. Now simply run another command to start the project:
yarn dev
You would see your browser opening URL http://localhost:8080/docs
. If it does not check the terminal [CLI] which would show logs as shown in below.
Index: Working on Development Mode.
π‘ Server is running in Development mode
π Setting up HTTP Server
π Swagger Documentation is available at http://localhost:8080/docs/
π Swagger Documentation is available at http://localhost:8080/docs/
π Configuring HTTP Routes
π Establishing API Controller [Auth] at [/api/auth/] with E:/Practice/authJs/backend/controllers/api/Auth.js
Index: Working on Development Mode.
π‘ Server is running in Development mode
Index: Working on Development Mode.
π‘ Server is running in Development mode
π Setting up HTTP Server
π Swagger Documentation is available at http://localhost:8080/docs/
π Swagger Documentation is available at http://localhost:8080/docs/
π Configuring HTTP Routes
π Establishing API Controller [Auth] at [/api/auth/] with E:/Practice/authJs/backend/controllers/api/Auth.js
π Establishing API Controller [User] at [/api/user/] with E:/Practice/authJs/backend/controllers/api/User.js
π Connection Established, Serving HTTP with URL [http://localhost:8080]
Open your browser navigate to http://localhost:8080/docs
URl and you are good to go.
- backend directory -> All the web/api controllers.
- configuration directory -> All the Configurations.
- database directory -> All the Scripts and Database files.
- documents directory -> All necessary images and documents.
- library directory -> All custom written Codes
- node_modules -> All the packages and dependencies.
index.js
file is the initial file that server requires whereas cleanup.js
file is used to remove create a fresh setup of project wiping all information in database.
yarn clean
or yarn setup
unless you want a fresh setup.
When you navigate to browser and open http://localhost:8080/docs
you will see.
Every endpoints requires a csrf token which can be obtained from http://localhost:8080/api/auth/csrf
and every user routs along with login_check
routes requires Authorization header which can be achieved once you hit http://localhost:8080/api/auth/login
route.
When you see following message in console it means a PORT conflict has arise.
node:events:371
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE: address already in use :::8080
at Server.setupListenHandle [as _listen2] (node:net:1319:16)
at listenInCluster (node:net:1367:12)
at Server.listen (node:net:1454:7)
at Function.listen (F:\AuthJs\node_modules\express\lib\application.js:635:24)
at Server.#listenHttp (F:\AuthJs\library\server\lib.server.express.js:418:14)
at Server.setupHTTP (F:\AuthJs\library\server\lib.server.express.js:521:25)
at Server.setUpServer (F:\AuthJs\library\server\lib.server.express.js:535:31)
at Object.<anonymous> (F:\AuthJs\index.js:85:6)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
Emitted 'error' event on Server instance at:
at emitErrorNT (node:net:1346:8)
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
code: 'EADDRINUSE',
errno: -4091,
syscall: 'listen',
address: '::',
port: 8080
}
To Fix this issue we have different solution as per the operating system.
Find PID using following command
lsof -i TCP:8080 | grep LISTEN
It would result in something like
node 2464 user 21u IPv6 4392639 0t0 TCP *:http-alt
The Second colum after node is PID, kill the PID using following command
kill -9 2464
Find the PID using following command
netstat -ano | findstr :8080
WHich would return something like
TCP 0.0.0.0:8080 0.0.0.0:0 LISTENING 24552
TCP [::]:8080 [::]:0 LISTENING 24552
Kill the PID at last after LISTENING using following command
taskkill /PID 24552 /F
If you have any issues please contact me at:
Email : dibeshrsubedi@gmail.com LinkedIn : https://www.linkedin.com/in/itsubedibesh
Checkout https://github.com/Sniper-Code/AuthJs/issues for any issues or to fill an issue.