Danial Khosravi's Blog

Entrepreneur in the making...

Simple Authentication in NodeJS

| Comments

Hi everyone !!

Today i’m going to show you my simple authentication practice. There is lots of good authentication modules out there which can be used as middleware like PassportJS and Everyauth and they are also very useful for integration your web site with social networks like Facebook and Twitter. I will cover both the mentions tools in future posts but today we are going to build our authentication functionality on our own !!

Before we start I should mention that like always I used MongoDB as a database for saving and loading our users. And I integrate it with our app using Mongoose module. So make sure you have them installed or if you using my source files first run npm install . Also make sure you are running mongo server by running mongod in new shell.

Application Parts

  • Module Dependencies
  • Database and Models
  • Middlewares and configurations
  • Helper Functions
  • Routes

Simple Node Server

| Comments


In my first post on my brand new blog I want to talk about my new discoveries on NodeJS. As you can see in NodeJs site :

Node.js is a platform built on Chrome’s JavaScript runtime for easily building fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices.

Its a lot great features that all are 100% JavaScript . Definitely it’s a great choice for a beginner like me that only know a bit of JavaScrip. With Node you can run your server side JavaScript codes easily !!

What We Are Going To See?

I’m going to show you how to make a simple server. For now I just render two pages on this server, home and about. It’s all with pure NodeJS and I don’t use any framework. If you are familiar with amazing framework of NodeJS, Express you would say it could be much more easier with Express. I agree but I believe first we should learn how to deal with NodeJS and after that go for frameworks.

By the way i’m going to cover Express in future posts in this blog !!