fabiochiu/medium-articles huggingface dataset:
Redis
By: Enes Baki Si̇rmen
Tags: NoSQL, Redis

Learn more. Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Make Medium yours. Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore
NoSQL Veritabanları
By: Furkan Kaplan
Tags: NoSQL

Learn more. Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Make Medium yours. Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore
Many-to-many relationship in NoSQL database
By: Rodrigo Palermo
Tags: Many To Many Relationship, NoSQL, Mongoose

Using mongoose to create a many-to-many relationship

I am taking a course on programming analysis and development, and one of my tasks is to write something that I’ve learned and is useful for other students. One of my current programming projects is about online courses. The main goal is to connect student to teachers. A teacher sign in to the site and offers his courses to students. A student sign in to the site and can search, subscribe and unsubscribe to courses. Maybe you’ve already did a project like this one with a relational database (SQL). In order to study and use a non-relational database (NoSQL), here I am going to use the library mongoose, a mongoDB object modeling for node.js.

Precisely, in this post I’ll show you how to deal with a many-to-many relationship with mongoose. Let’s take, for example, a student that wants to subscribe to a course. Many-to-many in this case means a student can subscribe to many courses, and a course can be subscribed by many students. Concerning a relational database, a basic Entity-Relationship (ER) conceptual model is represented below.

ER conceptual model

A logical model showing the many-to-many (M:N) relationship is represented below.

ER logical model

The tables needed to be created in a SQL database include a ‘student’ table, a ‘course’ table and a third table that represents the many-to-many relationship, called, for example, ‘student_course’. This table must have primary keys columns (PK) with the ids of the student (student_id) and the course (course_id), as showed on the figure:
Gluu wins 2020 Couchbase Independent Partner of the Year Award
By: Gluu Federation
Tags: Gluu Server, Couchbase Award, NoSQL, Identity

Gluu wins 2020 Couchbase Independent Partner of the Year Award

Couchbase, the creator of the enterprise-class, multi-cloud NoSQL database, today announced at the Connect Conference that Gluu was acknowledged with the Couchbase Independent Software Vendor Partner of the Year Award. Guest judges for the Couchbase Community Awards included Carl Olofson, Research Vice President at IDC, and Jon Reed, Co-Founder of Diginomica.

Open to Couchbase’s network of more than 300 partners, the award recognizes partners’ work in bringing differentiation and innovation to customers, and leading them to successful outcomes.

The Couchbase database is used for Gluu Server authentication and authorization requirements that requires extreme concurrency and “active-active” multi-datacenter replication. “Couchbase and cloud native technology has enabled Gluu for the first time to achieve true horizontal auto-scaling,” said Michael Schwartz, CEO of Gluu. “It’s a great honor to win this award, because it recognizes the sustained efforts of our combined engineering teams to make this accomplishment a reality. Couchbase has enabled Gluu to make performance into a competitive advantage. We’re crushing the competition in both transactions per second and total cost of ownership. You can’t do this stuff with ancient LDAP servers, no matter how much lipstick you put on them.”

Learn more from Gluu and Couchbase’s previous joint press release:

Open Source Gluu Server and Couchbase Shatter Billion-Login-Per-Day Threshold

“We are excited to not only continue, but to strengthen our long-standing partnership with Gluu,” said Matt McDonough, Vice President of Business Development at Couchbase. “Through Couchbase and Gluu’s cloud native approach, we’ve been able to split services and workloads to support auto-scaling easily enough to surpass the 1B authentications in a single day milestone. Together, we will continue to optimize the Couchbase platform along with Gluu’s robust, industry-proven solution for single sign-on and two-factor authentication to deliver the next billion authentications in a day.”

Read the press release:

http://www.globenewswire.com/news-release/2020/10/15/2109259/0/en/UPS-Tesco-and-Infosys-Among-Winners-of-Inaugural-Couchbase-Community-Awards-and-2020-Couchbase-Partner-Awards.html
Cosmos DB: 4 Things You Should Know
By: Thomas Shallenberger
Tags: Typescript, Azure, Cosmos, Database, NoSQL

1. Change Your Paradigm

If you are like me, you’re most likely coming from a primarily SQL dominated workplace and background. You’re used to building schema’s with data models, focusing on normalization of data, and performing migrations when the data model or schema changes.

Throw all that out the window. You’re in NoSQL land now.

Since Cosmos DB stores JSON documents, when you save an entity to a collection, you store the entity with all of its child entity properties (watch out for circular references here when serializing your entities before storage).

Additionally, this means no more normalization of data. While this may make you wince, consider all of the performance savings you made from no longer having to make expensive joins across tables.

Since this NoSQL database no longer cares about relationships, there are no longer any constraints (beyond having a partition key, and any unique key you decide to specify on creation of the collection). So your data migration is simply an update of the model used to serialize data before storage. No more SQL database schema migrations! Your model can now adapt and evolve much faster than before with changing business requirements.

Developer beware: this means there must be nullable fields for all properties, as they can go missing with a single model update. Your front end developer/API consumer must be made aware of each model update so they don’t get caught out when they attempt to build their UI around your models.

I’ll also say that although you can create multiple collections in a database, typically you don’t want to store only one type of entity in that collection. Use discriminators to distinguish between entity types, and partition keys to segment groups of entities to really harness the type of performance of which Cosmos DB is capable.

It’s not all roses in NoSQL land, though. There is a constraint, one that I overlooked at first, and came around to bite me in the end…
Update MongoDB data as like as where clause
By: Fahad Ahammed
Tags: Mongo, Mongodb, Mongo Shell, NoSQL

{"_id": **, "status": "SOLD"}

{"_id": **, "status": "SOLD"}

I need those to be

{"_id": **, "status": "INACTIVE"}

{"_id": **, "status": "INACTIVE"}

How? The answer should be updateMany

try {

db.COLLECTION.updateMany(

{status: "SOLD"},

{$set: {current_value: "INACTIVE"}}

);

} catch (e) {

print(e);

}

Here, first field {status: “SOLD”} is the condition as “where” clause. Then I had to use “$set” to the desired one. I hope you understand.
What is Firebase?
By: Tanner Townsend
Tags: Backend, NoSQL, Firebase, React

I was creating a Netflix clone for a project I was working on when I first started to use Firebase. So, I needed user authentication and a cloud database. Let’s see how easy it was to get Firebase attached to my application.

I created a Firebase application on the Firebase console.

Firebase project creation

2. I installed Firebase in my project with npm install firebase

3. I created a seed file called seed.js with my data in JSON format.

seed.js

lib/firebase.prod.js

4. I created a file in my project called firebase.prod.js for my Firebase connection. This is where I also seeded my database. This will NOT run until step 5 is completed.

Be careful to only run the seedDatabase(firebase) line only one time and then remove it AFTER step 5 or you will have duplicates in your database.

Populated seed data in the Cloud Firestore

index.js

5. We have to connect Firebase to our project in the index.js using context. We wrap our app around the Firebase context provider.

pages/signin.js

6. Since we are using React context, we are able to connect our Firebase context to any page without props . So, we use the firebase methods within our handleSignin method to authenticate the user and sign them in with their email and password.

If it is successful, we push them to the browse page else, we handle the error.

Firebase website

7. On The Firebase website, we have to go to the authentication tab. Then, we have to go to Sign-in method. Then, ensure that Email/Password is enabled.

hooks/use-content.js

8. Now it’s time to get the content from the cloud Firestore and utilize it. This method takes in a ‘target’ which is a collection name and return an array of the content for that target.

Collections Available: Films, Series. Each have 25 items in them. These arrays are then returned to the browse page where they are displayed.

pages/browse.js

Snippet of the cards in the BrowserContainer (containers/browse.js)

In Conclusion, I learned a ton about the Firestore and how it makes a backend so much easier. I know this seems like a lot of code and effort to just get user authentication and a database but, it doesn’t take as long as it seems and it will get much easier with practice. Using Firebase cuts out all of the backend work and lets users focus on the frontend which is awesome!
Referencing dan Embedding di MongoDB
By: Rivan Devrianza
Tags: Coding, Database, Mongodb, NoSQL, Programming

Data Modeling Introduction - MongoDB Manual

The key challenge in data modeling is balancing the needs of the application, the performance characteristics of the…
Convert/Unconvert using @DynamoDBTypeConverted Annotation
By: Varsha Venkatesh
Tags: Aws Sdk, Dynamodb, NoSQL, Java, Aws Dynamodb

@DynamoDBTypeConverted annotation is used to transform data before writing and after reading from DynamoDB.

This is the ideal place to put in logic to convert data before storing to DB and un-convert back while reading data into your application.

Let’s take an example of using @DynamoDBTypeConverted to create a custom annotation that can be used to encrypt sensitive fields in the database and decrypt back when the data is read through the application. This way the sensitive data would be encrypted when engineers use DynamoDB console for any reason and the encryption key used is generated by your application and not by DynamoDB.

Note: This is different from turning on encryption at rest for the entire table

Step 1: Creating @Encrypted custom annotation in Java

@Target({ElementType.FIELD})

@Retention(RetentionPolicy.RUNTIME)

@DynamoDBTypeConverted(converter= Encrypted.Converter.class)

public @interface Encrypted {



RootKey rootKeyName();



class Converter implements DynamoDBTypeConverter<String, String>

{

private RootKey rootKey;

private EncryptionService encryptionService;



public Converter(final Class<String> targetType, final Encrypted annotation) {

this.rootKey = annotation.rootKeyName();

initEncryptionService();

}



public Converter() {

this.rootKey = null;

initEncryptionService();

} private void initEncryptionService() {

// initialize your Encryption Service } @Override

public String convert(final String s) {

return encryptionService.encrypt(s, this.rootKey);

}



@Override

public String unconvert(final String s) {

return encryptionService.decrypt(s, this.rootKey);

}

}

}

Step 2: Use @Encrypted in entity class to annotate sensitive fields

@DynamoDBTable(tableName="contact")

public class Contact {



@DynamoDBHashKey(attributeName="contactId")

private String id;



private String firstName;



private String lastName;



.... @Encrypted(rootKeyName = RootKey.secretField)

private String secretField;

}

This method of writing custom annotations becomes super useful in practical applications when we want the data format in the DB to be different from the data used in the application!
Laravel + MongoDB
By: Sarinthon Mangkorn-Ngam
Tags: Laravel, Database, Web, Mongodb, NoSQL

jenssegers/laravel-mongodb

This package adds functionalities to the Eloquent model and Query builder for MongoDB, using the original Laravel API…
Using NoSQL instead of SQL, so Why?
By: Kurt F.
Tags: Data Science, Data Analysis, Data Management, NoSQL, Sql

Photo by Austin Distel on Unsplash

Using NoSQL instead of SQL, so Why?

The concept of NoSQL, which we have begun to hear frequently recently, has emerged as an alternative to relational database systems (RDBMS), which have been indispensable in the informatics world for years.

At the same time, it is the general name given to horizontally scalable systems that have emerged in order to store the increasing data of the internet and to meet the needs of systems with high traffic.

Since the SQL language used in RDBMS is not used in NoSQL systems, it is named “No SQL”. It is sometimes referred to as “Not Only SQL”, although it has somehow held a place in the market, but is not yet accepted as an industry standard. In fact, discussions are inevitable, as always when talking about which technology is best to solve business problems.

And still today, IT professionals do not yet have a common opinion on the concept of NoSQL.

There are some facts the debate is based on:

Google and Amazon keep internet data on Big Table, not RDBMS. (i.e. NoSQL systems)

Storing large volumes of data without structure. A NoSQL database doesn’t limit storable data types

Using cloud computing and storage. Cloud-based storage is a great solution, but it requires data to be easily spread across multiple servers for scaling.

And rapid development.

How are NoSQL systems different from RDBMS?

7 Reasons

1.RDBMS are transaction-based systems.

2. There is no “transaction” concept in NoSQL system.

3. Performance gain is aimed with horizontal growth in NoSQL systems.

4. While data in RDBMS are found in tables, in defined columns row by row, NoSQL systems are not dependent on fixed table definitions.

5. In RDBMS, data is regularly normalized to separate tables according to their relationships, and a join is used to access data in this process.

6. In RDBMS, it is not necessary to separate the data from each other with a single primary key. However, NoSQL systems basically access data through singular keys.

7. Some of the NoSQL systems have map reduce capability. In this way, analyzes that are very complex to be performed with SQL on RDBMS can be easily performed with map reduce.

So what are the pros and cons of NoSQL systems?

7 Effects

1.NoSQL systems offer high accessibility. In terms of reading and writing performances, they can be relatively more efficient than RDBMSs.

2. Due to their flexible structure, they provide convenience in terms of programming and maintenance.

3. Since most of them are open source and suitable for cloud computing, they are cost effective.

4. However, it will be difficult to adapt applications using RDBMS systems to NoSQL systems at first. Even if the data is successfully moved, codes that use merging will need to be changed.

5. Likewise, it may be necessary to provide key-based data access instead of query-based data access.

6. They do not yet have advanced features in data security as much as RDBMSs.

7. Documentation and professional support may not be sufficient in some projects.
SQL and NoSQL for Flutter
By: Khurshidbek Kurbanov
Tags: Database, Flutter, Hive, NoSQL, Sql

Jumping into the Flutter was not a big issue since I have been working on Android and iOS for a couple of years. Its configuration was pretty straightforward and only you have to do is adapting to use declarative programming. Choosing the right database for the mobile application has always been a big challenge. There are a lot of options such as SQL (SQLite), NoSQL (Realm) out there today when it comes to databases in Native App.

Let’s look at some of the options we have on Flutter for SQL and NoSQL databases today. If you are not familiar with what NoSQL databases are or the different types of NoSQL databases, start here.

SQL databases: SQLite, Floor, Moor

NoSQL databases: ObjectDB, Sembast, Hive

As I have mentioned above we have a whole lot of options for Flutter local database. Among those options I am gonna stick with Moor and Hive.

Moor lets you write queries in both SQL and Dart, providing fluent APIs for both languages. Moor is a SQLite abstraction.

Hive is an extremely fast and secure NoSQL storage option for Flutter developers. Hive is written in pure Dart.

There has not an easy way to answer what database is best — it depends on your use case.

If your data is relational and you do not mind not having web support, then you should use Moor .

. If you want to be up and running quickly and want support for the web plus anything else Dart runs on, then you should use Hive.

Since I have been using a NoSQL database for Native Android and iOS Development, I prefer to use Hive for Flutter. Based on the benchmark below you will be able to check every difference between SQL and NoSQL. If you are just after a simple database to store values or objects on your device and if you want something that works anywhere, Hive is for you.
Up and Running with AWS Neptune
By: Andries Van Humbeeck
Tags: AWS, Aws Neptune, Graph Database, NoSQL

This blog has moved to CodeMine.be

Read it here
The great debate: sql vs nosql
By: Hamza Shujaat
Tags: Software Architecture, NoSQL, Database, Sql

Looking at the above features we can get a rough idea of when a nosql database can be a good fit e.g a photo-upoading app (like Instagram), with a million users, can benefit massively from a horizontally scalable, distributed DB like mongodb or cassandra. But suppose we want to build a talent assesment tool for a multinational conglomerate, where consistency of data is key (since millions of dollars worth of bonuses given to people will depend on the data stored in our tool), in such a case a traditional RDBMS like MySQL will be a better fit with it’s ACID compliant transaction support.

But let’s discuss the “normalized” and “denormalized” schemas that are a good fit for each type of DB. Firstly let’s discuss the traditional “normalized” schema that is so popular for use with Relational Databases:

As is evident from the above diagram, in a traditional normalized schema, while following all the rules of normalization we do not keep redundant data in the database. We instead use unique ids as foreign keys and enforce certain contraints to make sure the data is exactly as we want it. As a result of this while writing or changing the data we need to update it ,ideally, in one place only making sure data is as consistent as possible. The downside to this is that while retrieving the data we might have to perform a complex join operation which can result in performance issues when size of the tables is very large.

Now let’s take a look at the denormalized schema used mostly with nosql data bases.

As you can probably see from this diagram, in the denormalized schema instead of (or in some cases in addition to) the unique user Id we are storing the name of the user directly in the company table(collection in this case). This results in there being no need to perform a complex join operation when retrieving the company with the name of the user. The downside, however, is that now while updating the data we will need to perform two separate operations to modify the data in each table. This combined with the fact that nosql databases usually don’t come with transaction support , there is a real risk of our data being modified to an inconsistent state (In the case that update occurs on one table but fails on the other).

I hope by reading the above article you will have had some clarity on which database to use for your whatever you are developing.
ElasticSearch: the what?
By: Riddhi Nisar
Tags: Search, Introduction, Elasticsearch, Indexing, NoSQL

So, at the end of the day, WHAT is ElasticSearch? Well, as the official tagline says: You know, for search! (and analysis) 😁

PS: Be on the lookout for ElasticSearch: the why and the how for more! 📖
A Minimal Node.js, Express, & Babel Setup: Part 1
By: Nate Jones
Tags: Nodejs, Web Development, Expressjs, Babel, JavaScript

Let’s set up a basic Node.js / Express.js API that uses Babel. Babel will ‘transpile’ our ES2015+ code and module syntax to older-style code for compatibility purposes. I’ll use a basic Express API as the example, add in absolute imports via Babel, and briefly discuss whether we even need Babel in 2020 for our Node setup.

In Part 2 of this minimal setup, I’ll add in setup for eslint and prettier, and show you how to get them to play nicely together. Then we’ll update some settings in VS Code to finish the process.

The final repository can be found here:

1. Node Version & Express Skeleton

First, let’s take care of our Node version. I like to use nvm to manage my Node versions across different projects. Please follow the install instructions they provide.

We’ll use the “Current” release on nodejs.org, which is 15.4.0 as of the time of this writing. Run these 2 commands:

nvm install 15.4.0

nvm alias default 15.4.0

This installs Node version 15.4.0 to our list of nvm versions we have on our machine (run nvm ls to see which versions you have). We’ll one more piece of nvm configuration soon, but let’s move on to the code.

To get our code off the ground, we’ll create a new project with the Express application generator (run in my fresh repo node-babel-template ):

npx express-generator .

This tool generates a super simple Express api for us ( bin/www is the entry file, app.js sets up the Express app, and there are a couple simple route handlers in the routes directories).

How can we specify which Node version we want to use with our project?

Create a file at the root of the project called .nvmrc and simply put 15.4.0 in the file. In your terminal, in the project root directory, type nvm use — this command tells nvm to look for the .nvmrc file and use the version specified In your package.json , add a section called engines that looks like this:
Mengenal Proses Asinkronus dan Implementasi Worker Thread di Express JS
By: Rian Yulianto W
Tags: Nodejs, Multithreading, Jwt Token, Expressjs, JavaScript

Learn more. Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Make Medium yours. Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore
How to Deploy an Express Project to the Server?
Tags: Nodejs, Backend Development, Web Development, Expressjs, China

What is Express

Express is a Node.js based web development framework. It is very fast and simple to build a sites’s backend with Express.

21YunBox provides you with a simple Express deployment method with in China. You can deploy with 21YunBox in the Node environment.

How to Deploy Express in China

Register as a 21YunBox member Fork express example Create a Cloud Service on 21YunBox, and allow 21YunBox to access your code base (repo) Create with the following configuration

If you’d like a step by step example, please refer to this video: How to deploy Express to the server?

Why Choose 21YunBox?

21YunBox is a Cloud Service platform based out of Beijing. Our services enable your team to be more effective in leveraging the growing opportunity within China by hosting your sites at blazing speeds with an operational and maintenance free, and low code solution. 21YunBox provides an easy and budget friendly, end-to-end web platform deployment service for all applications from small teams to large enterprises. We also offer full support in obtaining your ICP license allowing you to legally host online content inside of Mainland China.

To learn about the differences between 21YunBox and these foreign (outside of China) cloud service platforms? You can refer to:
Cookies🍪, lets bake this happen
By: Charlie K
Tags: Security, Cookies, Web Development, Expressjs, JavaScript

Setting up Http Cookies using Express JS for your application

What are cookies?

Cookies

Cookies are small files that websites send to your device that the sites then use to monitor your user activities, session management and for personalization.

A cookie generally contains the information as a string generally in the form of a key-value pair and remembers the user’s information among all web pages in a browser.

How cookies work

When a user sends a request to server say by visiting a website that request is treated as a new request. The server in our case the backend attaches a cookie to the request so that when a user makes a future request the server recognizes the user from the cookie.

Requirements:

· Node installed

· Text editor

· Chrome browser

Setup

We will be using npm package express for setting up our server and cookie-parser

On the terminal use the command to install express and cookie-parser

npm install express cookie-parser
Filtering, Sorting, dan Pagination dengan Sequelize ORM
By: Ziady Mubaraq
Tags: Nodejs, Expressjs, Sequelize

in Level Up and Launch
Node.js PostgreSQL CRUD example: Rest APIs with Express & Sequelize
Tags: Nodejs, Sequelize, Postgres, Postgresql, Expressjs

In this tutorial, I will show you step by step to build Node.js PostgreSQL CRUD Restful API example using Express and Sequelize.

Node.js PostgreSQL CRUD Rest API overview

We will build Rest Apis that can create, retrieve, update, delete and find Tutorials by title.

First, we start with an Express web server. Next, we add configuration for PostgreSQL database, create Tutorial model with Sequelize, write the controller. Then we define routes for handling all CRUD operations (including custom finder).

The following table shows overview of the Rest APIs that will be exported:

POST /api/tutorials: create new Tutorial

GET /api/tutorials: retrieve all Tutorials

GET /api/tutorials/[id]: retrieve a Tutorial by :id

PUT /api/tutorials/[id]: update a Tutorial by :id

DELETE /api/tutorials/[id]: delete a Tutorial by :id

DELETE /api/tutorials: delete all Tutorials

GET /api/tutorials/published: find all published Tutorials

GET/api/tutorials?title=[keyword]: find all Tutorials which title contains keyword

Finally, we’re gonna test the Rest Apis using Postman.

This is our project structure:

Demo Video

This is our Node.js PostgreSQL CRUD example using Express & Sequelize application demo, test Rest Apis with Postman.

Test the APIs

Run our Node.js application with command: node server.js .

Using Postman, we’re gonna test all the Apis above.

Create a new Tutorial using POST /tutorials Api

Retrieve all Tutorials using GET /tutorials Api

Retrieve a single Tutorial by id using GET /tutorials/:id Api

Update a Tutorial using PUT /tutorials/:id Api

Find all Tutorials which title contains ‘js’: GET /tutorials?title=js

Find all published Tutorials using GET /tutorials/published Api

Delete a Tutorial using DELETE /tutorials/:id Api

Delete all Tutorials using DELETE /tutorials Api

For more details, implementation and Github, please visit:

https://bezkoder.com/node-express-sequelize-postgresql/

For more details, implementation and Github, please visit:

https://bezkoder.com/node-express-sequelize-postgresql/

For Server-side Pagination:

Node.js Express Pagination with PostgreSQL example

You can also find how to build a fullstack system with this app as backend server in the posts:

– Vue.js + Node.js Express + PostgreSQL example

– Angular 8 + Node.js Express + PostgreSQL example

– Angular 10 + Node.js Express + PostgreSQL example

– Angular 11 + Node.js Express + PostgreSQL example

– React + Node.js Express + PostgreSQL example

Or Security: Node.js JWT Authentication & Authorization with PostgreSQL example
How to Hide API Keys of Your JavaScript Projects? (Secure & Easy Way / No .ENV File)
By: Murat Umutlu
Tags: Nodejs, Expressjs, Security

While developing SPA project, we sometimes need to use API keys. Although it is possible to hide these API keys with .ENV file importing method, you must find another method on production process because of the fact that:

.env files’ content are visible to client when they investigate your .js files.

.env importing is used for when you want to hide api key on Github 🙂

Quick fix for this problem:

You can try to create a new express.js project to get request from your client then forward this request this to 3rd party endpoint with API key (on backend side).

After it gets response from 3rd party endpoint, your express.js backend project must forward this response to you.

Here you can find my solution and steps:
So you want to hide your API keys securely?
By: Jasmine Hatcher
Tags: Nodejs, Security, API, Axios, Expressjs

Frequently when working with APIs, you’re going to be provided with a unique token or key that allows you to access the data provided by that API endpoint. Sometimes, to access this endpoint you will also need to provide your credit card information. This makes the need for hiding your token or key even more important, if you upload that key to your GitHub a bad actor can find it, access it and use it to run up your bill. We want to prevent that from happening at all costs, so we should invest in a bit of security.

We are going to create a .env file and add it to our .gitignore file so it’s never tracked in git.

In our .env we will declare and customize our environment variables. This is where we will place our API keys and tokens. See the example below, think of the environment variable as a key value pair, your key will be an alias that you will use throughout your code to securely reference the value of your token.

To access our keys we will need to install the dotenv module from npm, this module tells the server to load anything that’s in a .env file to an environment variable.

At the topmost file of your application most likely your index.js where you initialize express you’re going to want to require the dotenv module.

Once that’s done you can now access any tokens or keys that you’ve placed in your .env file through process.env .

After much research, I found that the most secure way to make your request to the API endpoint you want to use is from your own server routes. This can be done by making an Axios HTTP request inside your route. Once you’ve got the skeleton of your route set up create variables to hold your keys.

Then you want to configure your request to include the key, the url, and any additional requirements (the host, params, querys, etc.)

Then you can test your routes in your browser or using postman.

Once you’ve confirmed that your request is successful, you can access that data on your client side with an Axios request to your newly created express route from your redux store, react component, etc. Use that data to make your page responsive, dynamic, interactive, whatever you wish.

When I was ready to deploy my app I used Heroku. Heroku has a feature called config vars that allows you to store your environment variables securely to move your app from development to production. Copy your key value pairs from your .env file to the config vars section of your settings.
Server Side Rendering React App with Express
By: Oğuzhan Kurtuluş
Tags: Server Side Rendering, Expressjs, Webpack, Babeljs, React

I know you have already understood the whole webpack configurations.. Then now let’s start to save our packages.

npm install express @babel/cli @babel/core @babel/polyfill isomorphic-style-loader react-redux redux webpack webpack-node-externals

Your dependencies list would be like this;

SSR React Dependencies

Also you should care about two important points. One of them is “engines” key, another one is “script” key. You should write correct values for these keys. Just follow below…

SSR React package.json engine config

SSR React package.json scripts config

Finally our package.json is ready to fly… Yes, this was the smallest part of our implementation. Now lets create our webpack.config.js file. The most important part is to tell the entry and output points. Also your rules can change because of your CSS preloader.
2. blog_expressjs/app.js(Set view engine) 3. Create views folder(Default all ejs file stay on views folder) blog_expressjs/views/home.ejs 4. blog_expressjs/app.js ‘’Render to home.ejs’’ 5. npm start
By: Safaetul Ahasan
Tags: Nodejs, Node Js Tutorial, Software Engineer, View Engine, Expressjs

Install view engine:(Express.js support different types of view engine,ejs for beginner.)

npm i ejs

2. blog_expressjs/app.js(Set view engine)

app.set('view engine','ejs') //additional For different directory(Default all ejs file stay on views folder):

app.set('views','templet')

3. Create views folder(Default all ejs file stay on views folder)

mkdir views

cd views

vim home.ejs

blog_expressjs/views/home.ejs

<!doctype html>

<html lang="en">

<head> </head>

<body>

<h1>Hello, world!</h1> </body>

</html>

4. blog_expressjs/app.js

‘’Render to home.ejs’’

app.get('/', (req, res) => {

res.render('home')

}) ====================Full code================================= const express = require('express')

const morgan = require('morgan') //medillower function

const mongoose = require('mongoose') const app = express() //route handaling,controller,templet engine,middleware app.set('view engine','ejs') app.use(morgan('dev')) //middleware

app.use(express.urlencoded({extended: true})) // for get form data

app.use(express.json()) app.get('/', (req, res) => {

res.render('home')

}) mongoose.connect('mongodb://localhost:27017/test', {useNewUrlParser: true, useUnifiedTopology: true})

.then(() => { app.listen(4545, () => {

console.log('Connected')

})

})

.catch(e => {

console.log(e);

})

5. npm start
How to send sound (wav/mp3) with React Native to Node server.
By: Matt Gallik
Tags: Nodejs, Android App Development, Software Development, Expressjs, React Native

I was working on a quick side project where I needed to send audio from my android 📞 to my server 💻. Surprisingly, stack overflow did not have the answer straight away so here is a short article on how I solved this.

I am going to assume that you already have a server running and a react-native app running. I am also going to assume you have a way of talking between them. I used socket.io for my case but you might be using axios or a simple request.

Client

First lets get all our imports sorted:
Upload file with expressjs and multer — javascript
By: Nhan Cao
Tags: Expressjs, Multer

Config multer

// Multer upload config

const fs = require('fs');

const path = require('path');

const multer = require('multer');

const storage = multer.diskStorage({

destination: function (req, file, cb) {

cb(null, '/tmp/')

},

filename: function (req, file, cb) {

const uniqueSuffix = Date.now() + '-' + Math.round(Math.random() * 1E9)

cb(null, file.fieldname + '-' + uniqueSuffix + path.extname(file.originalname))

}

})

const upload = multer({storage: storage});

Single file

app.post('/uploadPhoto', (req, res, next) => {

upload.single('filename_here')(req, res, function (err) {

if (err) {

// A Multer error occurred when uploading.

res.json({msg: err.message})

} else {

// Everything went fine.

// req.file

// {

// fieldname: 'filename_here',

// originalname: 'nhancv_dep_trai.png',

// encoding: '7bit',

// mimetype: 'image/png',

// destination: '/tmp/',

// filename: 'filename_here-1607694392023-220481630',

// path: '/tmp/filename_here-1607694392023-220481630',

// size: 5907

// }

const file = req.file;

console.log(file);



// Delete tmp

try {

// fs.unlinkSync(file.path);

} catch (e) {

// Ignore

console.error(e);

}

res.json({msg: 'ok'});

}

});

})



Test

curl --location --request POST '<host>:<port>/uploadPhoto' \

--form 'filename_here=@"/Users/nhancv/Desktop/nhancv_dep_trai.png"'

Multi files

const fields = [{ name: 'front', maxCount: 1 }, { name: 'back', maxCount: 1 }]

app.post('/uploadPhoto', (req, res, next) => {

upload.fields(fields)(req, res, function (err) {

if (err) {

// A Multer error occurred when uploading.

res.json({msg: err.message})

} else {

// Everything went fine.

// file

// {

// fieldname: 'xxx',

// originalname: 'Screen Shot 2020-12-11 at 20.28.29.png',

// encoding: '7bit',

// mimetype: 'image/png',

// destination: '/tmp/',

// filename: 'xxx-1607694392023-220481630',

// path: '/tmp/xxx-1607694392023-220481630',

// size: 5907

// }



// array of `photos` files

const frontF = req.files['front'][0];

const backF = req.files['back'][0];

console.log('frontF', frontF);

console.log('backF', backF);



// Delete tmp

try {

// fs.unlinkSync(file.path);

} catch (e) {

// Ignore

console.error(e);

}

res.json({msg: 'ok'});

}

});

});



Test

curl --location --request POST '<host>:<port>/users/uploadPhotos' \

--header 'Authorization: Bearer <token>' \

--form 'front=@"/Users/nhancv/Desktop/nhancv_dep_trai_1.png"' \

--form 'back=@"/Users/nhancv/Desktop/nhancv_dep_trai_2.png"'

@nhancv
Node Testing: Jest + Supertest
By: Simon Karanja
Tags: Nodejs, Expressjs, Supertest, Jest

Now, first things first. Let’s create a minimal RESTful API that returns a cliché of todos. I will be using TypeScript and for simplicity, the todos will be stored on a plain file rather than a database. We will also use supertest for HTTP assertion. To follow along, clone the demo repo & switch to clean branch:-



git checkout clean git clone https://github.com/karanja-simon/node-jest-test.git git checkout clean

Should you get lost anywhere as we go along, you can quick switch to working branch ( git checkout master ) for the fully working demo.

Install tests dependencies

We will need to install jest, ts-jest and supertest:-

yarn add -D jest ts-jest supertest

Perhaps worth mentioning, ts-jest is a TypeScript preprocessor for jest that allows it to transpile TypeScript on the fly. In short, it allows you to test codebase written in TypeScript.

Since we are using typescript, let quickly add types:-

yarn add -D @types/jest @types/supertest

We also need to create a configuration that Jest is going to use when running our tests:-

jest --init

Based on your project, Jest will ask you a few questions and will create a basic configuration file with a short description for each option. Will also need to tell jest to use ts-jest . Finally, your config should look some thing like this:-

The tests

Of importance here is the todo.controller.ts that lives in src/api/controllers and our todo.service.ts in src/api/services. Since our controller is dependent on the service, lets first deal with the latter. Let’s see how our todo service looks like:-

This is a simple as any todo can get. With the spirit of unit testing, it’s clear that we need to test the three functions: allTodos() , todoById(id: number) and todoByStatus(status: string) .

Let’s fire our favorite editor and open the todo.service.test.ts in src/api/services/__tests__ and add the following:-

As with any Jest test, we wrap our test cases in describe , then implement our first test case, line 11–15. Since our allTodos() returns a promise, we pass async keyword in front of the function we pass to it . This tells jest to wait for the completion of the asynchronous code before executing the next test. We get the todo on line 18, then do our assertions with expect . If we run our tests:-

yarn test

We should see a healthy test run. You can also pass coverage flag to see the test coverage.

Notice we have 100% coverage, which is always a good sign.
Beginner: Node js, Express js, and Mongodb Installation Tutorial for Windows
By: Sari Arifin
Tags: Node Js Tutorial, Mongodb Installation, Expressjs, Beginner Javascript, Installation

1. Node JS Installation

In this tutorial, i’m going to share how to install node js in windows 10. First, you have go to nodejs.org official website or you can click here. Then you will see two options appear on your screen.

Here i’m going to use the left side or LTS which recommended for most users. You can click the option to download and once you have downloaded it, the next step is open the file. Then you just have to click next.

Then you will see that window. After you read the license agreement, you can click the check box I accept the terms in the License Agreement then click next.

Next choose the destination folder wherever you want, then just click next.

In the next page you just have to click next again.

After that click the check box and it will automatically install the chocolately that we will use for mongodb installation. Then just click next and click Install. It will need couple of seconds to install the program on your windows. And then you can click finish and power shell will appears on your screen to run the chocolately installation.

To ensure the node js installation is successed and see the version on your windows, open the command prompt on your windows or you just have to search ‘CMD’ on your windows and click run as administrator.

write the command line below

node -v

on your command prompt and you will see the version of your node

To test the runtime is worked you can write “node” and write some expression as shown below.

2. Mongodb Installation

As i say before, i will use chocolately to install mongodb in this tutorial, so ensure you have installed node js or chocolately first. Now we start to install Mongodb.

first open command prompt from your windows and run as administrator. Then write the following command line

choco install mongodb.install — version=4.0.7

or you can click here to see the detail information. In this case i use 4.0.7 version. If you want the latest version you can go to the official website of chocolately.

It took an hour to install (actually it depends on your speed) but mine sucks haha so it took a few hours.

If the installation is successed, you can check with the following command line

mongod

and you will see like this

3. Express JS Installation

This installation is the easiest in this tutorial. There are several options for installing the express, at command prompt or in code editor terminal. I usually use terminal on visual studio code but the command line is the same.

first write the command line below

Npm init

then

Npm install express

voila! you have express installed on your project. So thats the tutorial, if you have any questions you can leave a comment.
Error ‘blocked:csp’ using NodeJS, ExpressJS, and EJS
By: Zac Smith
Tags: Nodejs, Blocked Csp, Content Security Policy, Solution, Expressjs

You are chugging along, writing a server side application, for me using:

Node: 12.19.0

Cors: 2.8.5

Helmet: 4.2.0

Express: 4.17.1

Everything goes well until you refresh your app and it fails to load a linked image, and upon inspection you find something that looks like this!

Refused to load the image 'https://unsplash.it/200/200' because it violates the following Content Security Policy directive: "default-src 'self'"

Using your finally developed Google dorking skills you will find a dozens of explanations on what CSP does, how it improves security, and some sorta solutions. Nothing worked for me, until helmet() documentation was reviewed. All the articles and security documents tell you to modify the headers, or meta-tags but provide little in the way of solutions.
[MSA] Develop Gateway with Express.js
By: Daily Kiwi
Tags: Microservice Architecture, Gateway, Msa, Expressjs, Reverse Proxy

chimurai/http-proxy-middleware

Node.js proxying made simple. Configure proxy middleware with ease for connect, express, browser-sync and many more…
Why Anger is Important?
By: Mental. Health .Collective
Tags: Anger, Expressjs, Mental Health, Defender, Emotions

Anger is one of the most powerful and incredibly destructive emotions that is important for us to understand.

Anger involves physical and emotional energy where we experience a strong feeling of irritation or displeasure which our body prepares us to act.

It is up to us whether we use that energy in constructive ways or to abuse ourselves and those that we love.

It Anger helps to accomplish things though it sometimes takes all the blame. It tells us when we’re being mistreated. It's an important filter to remove all of the negativity in our minds at least momentarily which is peaceful and really important.

But remember, Anger itself is not necessarily a problem. It's how you choose to handle it.
Image uploading with Node & cloudinary made easy
By: Aditya Pahilwani
Tags: Cloudinary, Expressjs, Node, React

So today we are going to see how we can upload images to cloudinary from our backend, by converting the image to Base64 and then send it our backend to upload it

The Problem

As an react native dev, I thought to move to full-stack by creating an full-Stack Instagram clone, I was using React as frontend and most of the tutorials upload images directly from their frontend to cloudinary , I didn’t find it the right solution because I was planning to make the mobile version of it and it would result in re-writing that code again in react native

The Solution Approach

First I thought to use multipart/form-data but then I came up with more easy solution which was to convert the image to Base64 and send it to our backend and this Base64 was already present in our frontend for image Preview

Let’s get into code part

First we will dive into our frontend (made with React) and convert our image to Base64 which will be used for the image preview and also server as body to our API

const CreatePost = () => { const [imagePreview, setImagePreview] = useState(""); // Request to server const PostData = async () => { try { const res = await fetch("/your route", { method: "post", headers: { "Content-Type": "application/json", Authorization: AuthConfigForWeb(), }, body: JSON.stringify({ media: imagePreview, }), }); } catch (error) { console.log(error); } }; // Converting image to Base64 const setImgFunc = (e) => { if (e.target.files[0]) { const file = e.target.files[0]; setImage(file); let reader = new FileReader(); reader.readAsDataURL(file); reader.onloadend = () => { setImagePreview(reader.result); }; } }; return ( <div className="Create_Post_Card"> <div className="Upload_Image_Container" onClick={() => { fileRef.current.click(); }} > {!imagePreview ? ( <span className="Post_Title_Comment_Text">Upload Image</span> ) : ( <img src={imagePreview} className="Upload_Image" /> )} <input type="file" ref={fileRef} onChange={setImgFunc} hidden accept="imagePreview/*" /> </div> <button className="authButton" onClick={PostData}> Create </button> </div> ); };

We are done from our frontend , let’s setup our server code First we need to config cloudinary and export it

const cloudinary = require("cloudinary").v2; cloudinary.config({ cloud_name: cloud_name, api_key: cloud_api_key, api_secret: cloud_api_secret, }); module.exports = cloudinary;

Now let’s write our controller for the route

const cloudinary = require("../utils/cloudinary"); exports.yourFunc = async (req, res, next) => { const { media } = req.body; try { const mediaRes = await cloudinary.uploader.upload(media); console.log(mediaRes); } catch (err) { console.log(err); res.status(402).json({ error: err }); } };

And we are done now you can easily convert the image to Base64 and send it your server and upload to cloudinary

GitHub repository can be found here (Repo to my instagram clone from where the code was cropped)