<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: christosmito</title>
    <description>The latest articles on DEV Community by christosmito (@christosmito).</description>
    <link>https://dev.to/christosmito</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F383452%2F4ccbc460-50a7-439d-ba96-ab0fe2d15df8.jpeg</url>
      <title>DEV Community: christosmito</title>
      <link>https://dev.to/christosmito</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/christosmito"/>
    <language>en</language>
    <item>
      <title>Bottom values in Javascript </title>
      <dc:creator>christosmito</dc:creator>
      <pubDate>Sat, 01 May 2021 15:55:37 +0000</pubDate>
      <link>https://dev.to/christosmito/bottom-values-in-javascript-5349</link>
      <guid>https://dev.to/christosmito/bottom-values-in-javascript-5349</guid>
      <description>&lt;p&gt;&lt;strong&gt;Javascript&lt;/strong&gt; has two &lt;strong&gt;bottom&lt;/strong&gt; values. The &lt;strong&gt;null&lt;/strong&gt; and &lt;strong&gt;undefined&lt;/strong&gt; values are considered javascript's bottom values that indicate the &lt;em&gt;absence&lt;/em&gt; of a value. In addition, these values are the only values in javascript that are not object. Attempting to get a property from them raises an exception. Even though the &lt;strong&gt;null&lt;/strong&gt; is a well known value in other languages and it is commonly used, in javascript it is considered &lt;strong&gt;best practice&lt;/strong&gt; to use &lt;strong&gt;undefined&lt;/strong&gt; in most cases. First let's see the only case that we can use &lt;strong&gt;null&lt;/strong&gt; instead of &lt;strong&gt;undefined&lt;/strong&gt;. Using &lt;em&gt;Object.Create(null)&lt;/em&gt; in order to create a new empty object. So, why we should use &lt;strong&gt;undefined&lt;/strong&gt;? Because &lt;strong&gt;javascript&lt;/strong&gt; itself uses this value. If you define a non-initialize variable with let and var their values are undefined. If you do not pass enough arguments into a function, if you request a property from an object that lacks that property and if you get an element of an array that the array lacks, javascript gives &lt;strong&gt;undefined&lt;/strong&gt;. We can make &lt;em&gt;better programs&lt;/em&gt; if we eliminate one of them not from the language 😛 but from our programs&lt;/p&gt;

</description>
    </item>
    <item>
      <title>My first npm package about authentication</title>
      <dc:creator>christosmito</dc:creator>
      <pubDate>Tue, 27 Apr 2021 19:47:15 +0000</pubDate>
      <link>https://dev.to/christosmito/my-first-npm-package-about-authentication-oeh</link>
      <guid>https://dev.to/christosmito/my-first-npm-package-about-authentication-oeh</guid>
      <description>&lt;h1&gt;
  
  
  Intro
&lt;/h1&gt;

&lt;p&gt;I have been coding in Express and Mongodb about 1,5 years now and on every project I have built up until now I had to write the same code again and again in order to implement the authentication. Repetition is something we, as programmers, hate. So, for that reason I decided to make my own authentication package in order to implement the authentication flow and the DRY principle. &lt;/p&gt;

&lt;h1&gt;
  
  
  Implementation
&lt;/h1&gt;

&lt;p&gt;This npm package was built to be used with Express and Mongodb. The authentication is based on jwt. In  addition, sendgrid was used to implement the reset password functionality for sending an email with the reset token link.&lt;/p&gt;

&lt;h1&gt;
  
  
  Usage
&lt;/h1&gt;

&lt;p&gt;This package offers the below functionalities: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;signup&lt;/li&gt;
&lt;li&gt;login&lt;/li&gt;
&lt;li&gt;logout&lt;/li&gt;
&lt;li&gt;update password&lt;/li&gt;
&lt;li&gt;forgot password&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let's see how easily we can use this package:&lt;br&gt;
First we need to install the express-auth-flow package with this command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install express-auth-flow
or
yarn add express-auth-flow
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then we need to create a user model with the name of our choice and create at least these fields(the names must be exactly the same) as shown below:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;email&lt;/li&gt;
&lt;li&gt;username&lt;/li&gt;
&lt;li&gt;password&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Below is demonstrated a simple example using mongoose(it is highly recommended to validate all the fields)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//Model file userModel.js

const mongoose = require("mongoose");

const { Schema } = mongoose;

const userSchema = new Schema({
    email: String,
    username: String,
    password: String
});

module.exports = mongoose.model("User", userSchema);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now in your router file you must require your user's model you created above, the express-auth-flow package and make routes as below. The paths and the names must be exactly the same in order the package to recognize them. The email for the forgot password functionality are sent via sendgrid and you have to create a free account and then create an api key. An example is shown below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//Router file userRoutes.js

const express = require("express');

const User = require("The path to your user model");

const auth = require("express-auth-flow");

const router = express.Router();

//Only for forgot password functionality
const options = {
    apiKey: "your sendgrid api key",
    from: "your email that you verified on sendgrid",
    text: "The raw message",
    html: "The html formatted message"
};

router.post("/signup", auth("User").signup);
router.post("/login", auth("User").login);
router.post("/logout", auth("User").logout);
router.post("/update-password", auth("User").updatePassword);
router.post("/forgot-password", auth("User, options").forgotPassword);
router.post("/reset-password/:token", auth("User").resetPassword);

module.exports = router;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally lets analyze the inputs that are expected from every router&lt;/p&gt;

&lt;h3&gt;
  
  
  /signup
&lt;/h3&gt;

&lt;p&gt;The signup functionality is expect the below input:&lt;br&gt;
email, username, password, confirmPassword&lt;/p&gt;

&lt;h3&gt;
  
  
  /login
&lt;/h3&gt;

&lt;p&gt;The login functionality is expect the below input:&lt;br&gt;
email, password&lt;/p&gt;

&lt;h3&gt;
  
  
  /logout
&lt;/h3&gt;

&lt;p&gt;No input&lt;/p&gt;

&lt;h3&gt;
  
  
  /updatePassword:
&lt;/h3&gt;

&lt;p&gt;email, password, newPassword, confirmNewPassword&lt;/p&gt;

&lt;h3&gt;
  
  
  /forgot-password
&lt;/h3&gt;

&lt;p&gt;email&lt;/p&gt;

&lt;h3&gt;
  
  
  /reset-password/:token
&lt;/h3&gt;

&lt;p&gt;password, confirmPassword&lt;/p&gt;

&lt;h5&gt;
  
  
  Notice
&lt;/h5&gt;

&lt;p&gt;The forgot password functionality works like this:&lt;br&gt;
First the user goes to /forgot-password route and fills the&lt;br&gt;
email, password, newPassword, confirmNewPassword inputs. Then an email is sent to the provided email with a reset token link that is valid for 10 minutes and when the user redirects to this link must provide the password and the confirmPassword in order to save new password.&lt;/p&gt;

&lt;p&gt;In the near future I am going to release a video tutorial on how to use this package&lt;/p&gt;

&lt;p&gt;Thanks for your time and feel free to write any feedback. &lt;br&gt;
contact me at this email: &lt;a href="mailto:christosglx@hotmail.com"&gt;christosglx@hotmail.com&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>node</category>
      <category>authentication</category>
      <category>express</category>
    </item>
    <item>
      <title>Questions about personal project. MongoDB(Mongoose)</title>
      <dc:creator>christosmito</dc:creator>
      <pubDate>Wed, 29 Jul 2020 08:11:56 +0000</pubDate>
      <link>https://dev.to/christosmito/questions-about-personal-project-mongodb-mongoose-2fk2</link>
      <guid>https://dev.to/christosmito/questions-about-personal-project-mongodb-mongoose-2fk2</guid>
      <description>&lt;p&gt;Hello! I am considering to start a personal project both for demonstration and learning purposes. The technologies I am going to use is node.js(express.js) mongoDB(mongoose) and puppeteer. The project is that, I will scrape some sites and store the information in a database. For instance I will scrape some websites that sell tech stuff. I have some questions about the implementation. &lt;br&gt;
1) What is better? To store all the data to one single model or to construct different models for different categories. For example I will have a model for mobile phones a model for laptops and so on, or just one big model with a category attribute and write the category in it.&lt;br&gt;
2) Is any package or tutorial about partial text search in mongoDB or is better to use something like elasticSearch?&lt;br&gt;
3) In my example is it possible when the user search for a “general” product to return only the categories and not all the related products? For example if I search for iphone 11 in this site &lt;a href="https://www.skroutz.gr/c/40/kinhta-thlefwna.html?keyphrase=iphone+11"&gt;https://www.skroutz.gr/c/40/kinhta-thlefwna.html?keyphrase=iphone+11&lt;/a&gt; it will return only the deferent categories about iphone 11 and not all the products from all the stores. Is it possible in mongoDB?&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
