teleren/devto huggingface dataset:
How to use ES6 import syntax in Node.js
Tags: node, javascript, beginners, webdev
Published: 2021-04-08 09:00:22

A module is a JavaScript file that exports one or more values. The exported value can be a variable, an object, or a function.

An ES6 import syntax allows importing modules exported from a different JavaScript file. It is a common pattern to use modules across React and React Native applications. The syntax is composed of the following ES module standard:

```js
import XXX from 'xxx';
```

An ES module is the ECMAScript standard of working with modules. Node.js uses the CommonJS standard to import modules. The syntax for this type of standard can be described as:

```js
const XXX = require('xxx');
```

Node js doesn’t support ES6 import directly. Try writing the `import` syntax in a JS file:

```js
// index.js

import { ApolloServer, gql } from 'apollo-server';
```

Run the Node.js server either by using `npm start` or `npm run dev` and you will encounter the following error:

![ss1](https://i.imgur.com/lbHW7pl.png)

The solution to this error is in the first line of the above error snippet and is now [a recommend way by Node.js](https://nodejs.org/api/esm.html#esm_enabling). Set the `"type": "module"` in `package.json` file.

```json
{
  "type": "module"
}
```

This solution works for the latest Node.js versions (which is `15.4.x` at the time of writing) and versions above `14.x.x`.

![ss2](https://i.imgur.com/Mm92hul.png)

## What about environments using Node version lower than 14

Another solution to this problem is to use [Babel](https://babeljs.io/). It's a JavaScript compiler and allows you to write JS using the latest syntax. Babel is not framework or platform opinionated. This means that it can be used in any project that is written in JavaScript and thus, in a Node.js project as well.

Start by installing the following dev dependencies from a terminal window:

```bash
npm i -D @babel/core @babel/preset-env @babel/node
```

Then create a file at the root of the Node.js project called `babel.config.json` and add the following:

```json
{
  "presets": ["@babel/preset-env"]
}
```

The package `@babel/node` is a CLI utility that compiles JS code in a Node.js project with Babel presets and plugins before running it. It means it will read and apply any configuration mention in `babel.config.json` before executing the Node project.

Replace the `node` with `babel-node` to execute the server in the `start` or `dev` scripts.

An example of running Node server using `npm run dev` script:

```json
{
  "scripts": {
    "dev": "nodemon --exec babel-node server.js"
  }
}
```

---

> Cover image by [Jake Weirick](https://unsplash.com/photos/Q_RBVFFXR_g)
Copy of Scrapy Vs. Apache Nutch - Which is Better for Web Scraping?
Published: 2021-04-08 08:58:18

Here are the main differences between Scrapy and Nutch

Web crawling and scraping ideally should be separated so that any failures in scraping don't bring down the whole project, plus it is easier to address issues with each (there are so many) separately. Nutch does this, but with Scrapy, both the processes are linearly tied together.

Scrapy has built-in support for XPath & CSS selectors making web scraping a breeze.

Scrapy also provides an interactive shell console for trying out the CSS and XPath selectors making writing and debugging scrapers very easy.

Nutch has built-in support for a distributed file system (Hadoop) and graph database.

Scrapy deals with non-standard and broken encodings by detecting it automatically.

Scrapy has abstractions that simplify things like cookies handling, session handling, compression, authentication, caching, user-agent spoofing, rate limiting, concurrency support, crawl depth restrictions, etc.

Scrapy can also use the Scrapyd daemon to run multiple spiders at once. Combining Scrapyd and a rotating proxy API like Proxies API can allow you to scale web crawling projects to almost unlimited scale.
Copy of Web Crawling- Where Do I Start?
Published: 2021-04-08 08:57:34

This is an excellent question. Because well begun is half the battle.

The choice of framework depends on what your immediate needs are, the kind of website you need to scrape, and the limitations they have will make a big difference as well.

If you have no real compulsion there, I am always tempted to say Scrapy.

The Scrapy Framework provides all sorts of abstraction for common crawling issues like concurrent requests, using multiple spiders using Scrapyd, Managing crawling rules, Obeying site constraints like rate limiting, managing data with pipelines, and finally support for XPath and CSS selectors for scraping the data quickly.

But if you are dealing with a web site like TripAdvisor and you want to scrape their reviews, or ironically, even Quora, you will find that most of their content is loaded using AJAX calls so that Scrapy won't cut it. You will need to use a headless browser to render the javascript and then scrape the content. Puppeteer is the best option for this. It allows you to control an instance of Chromium using Node JS fully.

Between these two options, you are pretty well set. But production-level web scraping is mostly not about coding. It is about reliability. If you run a webcrawler or any scale and you want to run it frequently, and the data is mission-critical, you will find that most web servers are savvy enough to detect, warn and block your crawler quite easily.
YELPPPP. I mean HELPPPP

To overcome this, you will need to use a proxy service and code it in such a way you rotate between a few of them now and then. There are some places on the internet that you get a list of active proxies free like here https://www.proxynova.com/proxy-server-list/, or you can go for a professional Rotating Proxy API Service like Proxies API. Full disclosure: I am the founder of Proxies API.
How to write python program to calculate simple interest
Tags: python, pythonslearning, programming
Published: 2021-04-08 08:54:52

The <a href="https://pythonslearning.com/2021/03/how-to-write-python-program-to-calculate-simple-interest.html">Original article</a> link is Available so let's see :
We need to make sure that only numbers are inputted while asking for input.
To do that, I am going to put each input statement in its own while loop. The while loop will be exited when a number is inputted. Checking if the value inputted is correct is done by checking if it can be converted into a floating-point number. Since converting a string containing characters other than numbers into floating-point numbers results in a traceback, I am using try and except block to achieve this part.
In the try block I am trying to convert input into floating point value. If an error occurs then the flow jumps to except block where I am just going to ask the loop to continue. This goes on until a valid input is given.
For detailed coding see below original Article
<a href="https://pythonslearning.com/2021/03/how-to-write-python-program-to-calculate-simple-interest.html">How to write python program to calculate simple interest</a>
how to make your own MP3 music player in python using Tkinter
Tags: python, pythonslearning, programming
Published: 2021-04-08 08:33:23

The <a href="https://pythonslearning.com/2021/04/how-to-make-your-own-mp3-music-player-in-python-using-tkinter.html">Original article</a> like is available so let's see:
The media player is in dark theme with all the functionalities of a modern media player we can adjust the volume from the player switch back and front to previous and next songs. We can shuffle our playlist and also can move the song to any position as we want using the song slider.
from tkinter import *
import tkinter.ttk as ttk
import pygame
import os
from PIL import ImageTk,Image
import random
from tkinter import filedialog
import time
from mutagen.mp3 import MP3
See original post for detailed explanation <a href="https://pythonslearning.com/2021/04/how-to-make-your-own-mp3-music-player-in-python-using-tkinter.html">how to make your own MP3 music player in python using Tkinter</a>
Best of luck !!
KnexJS: how to convert a SQL join with aliases and ordered by values from another table
Tags: help, postgres, sql, javascript
Published: 2021-04-08 08:32:18

Hello DEV community,

I'm writing here as I'm a new in **KnexJS** query builder and need help to how to make a specific `SQL` script in KnexJS.

The script 

```sql
SELECT
	c.id,
	c.topic,
	c.origin_type,
	c.origin_id,
	c.created_at,
	MAX(m.updated_at) updated_at
FROM
	conversation AS c
	JOIN message m ON m.conversation_id = c.id
GROUP BY
	c.id,
	c.topic,
	c.origin_type,
	c.origin_id,
	c.created_at
ORDER BY
	updated_at DESC
```

The script joins 2 tables `message` and `conversation`.
The result is all conversations ordered by the last created_at message in message table 

example of an output result:

| id | topic | origin_type | origin_id | created_at                 | updated_at                    |
|----|-------|-------------|-----------|----------------------------|-------------------------------|
| 2  | xx    | aaa         | bbb       | 2021-04-07 14:47:55.55+00  | 2021-04-07 18:47:43.558+00    |
| 1  | xx    | aaa         | bbb       | 2021-04-07 14:37:45.446+00 | 2021-04-07 18:12:01.91+00     |
| 3  | xx    | aaa         | bbb       | 2021-04-07 14:48:04.055+00 | 2021-04-07 14:56:52.709884+00 |

The `updated_at` is deducted from the message table where the last created message as `created_at` gives which is the newest `updated_at` conversation.

All what I need is to convert to KnexJs but I have no idea how to make it.

I hope what I explained is understandable and hope to get some help with that so I may learn the ideal way  of doing it.

Thank you for yor time spent reading my help request :)
Increasing Product Release Velocity by Debugging and Testing in Production
Tags: testing, webinar
Published: 2021-04-08 08:18:37

Date || Time: 13 April 2021 | 10 AM PST

## Brief

Code faster. Test faster. Build faster. Deploy faster. Modern release cycles demand for pace and we do everything we can to ramp up our CI/CD pipeline and get those builds out ASAP. But just because your build passed all the right quality gates, it doesn’t mean you’re done. Production errors happen all the time and cause more and more damage the longer they linger.

In this webinar, Harshit Paul, Product & Growth Manager from LambdaTest and Idan Shatz, Developer Advocate at Ozcode, hitch up to show how both testing in Production and Production Debugging can truly get you to “DONE” so you can move on to the next build faster to increase your overall release velocity.

## What will you Learn

* Roadblocks to release velocity.
* How LambdaTest & OzCode can help accelerate go to market?
* Live Action — Demo 1 — Solving Cross Browser issues.
* Demo 2 — Solving complete E2E issues from Front-end to Back-end.
* Demo 3 — Testing & Debugging issues in production.
* Best practices to accelerate release velocity like a pro.
* Q&A session

**Register Your Seats Here:** [Increasing Product Release Velocity by Debugging and Testing in Production](https://www.lambdatest.com/webinar/increasing-product-release-velocity?utm_source=Codementor&utm_medium=Blog&utm_campaign=Rahul-8042021&utm_term=Rahul)
Request/Response Part 2: HTTP & The CRUD Controller
Published: 2021-04-08 08:14:55

## 1. HTTP, Request Methods and Response Codes

{% youtube 1sGG4c7pOlg %}

#### Request Methods

| Method | Action                                       
| ------ | ------------------------------------------- |
| GET    | Retrieve resource, no modification on server|
| POST   | Create resource                             |
| PUT    | Update resource                             |
| DELETE | Delete resource                             | 

[MDN Web Docs – HTTP request methods](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods)

#### Response Status Codes
| Code   | Action                                       
| ------ | ------------------------------------------- |
| 200 OK | Request successful |
| 201 CREATED | Request successful and resource has been created |
| 404 NOT FOUND    | Resource not found                             |
| 405 METHOD NOT ALLOWED| Request method is not allowed for the resource | 
[MDN Web Docs – HTTP response status codes](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status)

## 2. Specifying Allowed Request Method for Controller Mapping

{% youtube AlxgH028sV0 %}

[GitHub Repo Tag](https://github.com/softwaredevacademy/spring-web-app-demo/releases/tag/get-post-mapping)

#### Curl Command
```bash
curl -X POST localhost:8080/people/create/Alice/65
```

## 3. Adding a Request Body

{% youtube fcxR3u4cZYE %}

[GitHub Repo Tag](https://github.com/softwaredevacademy/spring-web-app-demo/commit/d70dc1780e0d897f89e7dae35044406ac493d4df)

#### Curl Command with Request Body
```bash
curl -iX POST --header "Content-Type: application/json" --data '{"name": "Alice", "age": 53}' localhost:8080/people/create/
```

## 4. Adding GET(individual resource), PUT and DELETE Mappings to Controller

As we add functionality to create, read, update and delete a resource to a controller, it becomes a so called _CRUD Controller_.

{% youtube rqn2Xx6gk8U %}

[GitHub Repo Tag](https://github.com/softwaredevacademy/spring-web-app-demo/releases/tag/crud-controller)

<hr>
<p style="align: center;"> <span> <a href="https://dev.to/softwaredevacademy/persistence-part-2-orm-3b7k">Previous article</a> | </span>
<span> <a href="https://dev.to/softwaredevacademy/entity-relationships-part-1-one-to-many-3ehg"> Next article </a> </span>
CodePen - Generative SVG Noise Grid Pattern Maker 🎨
Tags: codepen, webdev, javascript, design
Published: 2021-04-08 08:07:00

I'm a huge fan of these kinds of noisy grid patterns, and I wanted to add some to my in-progress personal site. Rather than tinkering away in Figma, I thought I would make a little generator. 

I hope some other folks find it useful! 🚀

{% codepen https://codepen.io/georgedoescode/pen/dyNVNjG %}
2021-04-07 | Facebook leak
Tags: learninpublic, beginners, webdev, privacy
Published: 2021-04-08 08:05:10

---
title: "2021-04-07 | Facebook leak"
description: "Summary of my day"
published: true
tags: ["LearnInPublic", "Beginners", "Webdev", "Privacy"]
series: "miku86 Diary"
canonical_url: "https://miku86.com/blog/2021-04-07"
---

You probably already heard about it: [533M Facebook users' data leaked](https://news.ycombinator.com/item?id=26681969).

So the Wikipedia articles about [Critism](https://en.wikipedia.org/wiki/Criticism_of_Facebook) and [Privacy concerns](https://en.wikipedia.org/wiki/Privacy_concerns_of_Facebook) of Facebook are already very long. One new chapter added.

In May, WhatsApp will [update their terms of service](https://www.dw.com/en/whatsapp-delays-privacy-changes-following-backlash/a-56243714), so Facebook will get your WhatsApp data.

Data of a mass surveillance tool (WhatsApp) in the hands of a company (Facebook) that sells and loses your data.

I think it's time to make a decision.

I made my decision some days ago, but it was in the making for a long time:

- [I deleted WhatsApp](https://miku86.com/blog/2021-04-02)
- [Why I deleted WhatsApp](https://miku86.com/blog/2021-04-03)
Add watermark to your PDF file with Python
Tags: python, tutorial, productivity, showdev
Published: 2021-04-08 07:58:31


Add watermark to your PDF file with Python

Today  I  will show you how you can simply add a  watermark to all pages within a  PDF  file.
I'll  use  `PyPDF2`

A Pure-Python library built as a PDF toolkit. It is capable of:

-   extracting document information (title, author, …)
-   splitting documents page by page
-   merging documents page by page
-   cropping pages
-   merging multiple pages into a single page
-   encrypting and decrypting PDF files
-   and more!

By being Pure-Python, it should run on any Python platform without any dependencies on external libraries. It can also work entirely on StringIO objects rather than file streams, allowing for PDF manipulation in memory. It is therefore a useful tool for websites that manage or manipulate PDFs.

Let's jump to the code

```python
from PyPDF2 import PdfFileMerger, PdfFileReader, PdfFileWriter

pdf_file = r'C:\Users\Stokry\Desktop\python\pdf\test1.pdf'
watermark = r'C:\Users\Stokry\Desktop\python\pdf\logopdf.pdf'
merged = r'C:\Users\Stokry\Desktop\python\pdf\merged.pdf'

with open(pdf_file, "rb") as input_file, open(watermark, "rb") as watermark_file:
    input_pdf = PdfFileReader(input_file)
    watermark_pdf = PdfFileReader(watermark_file)
    watermark_page = watermark_pdf.getPage(0)

    output = PdfFileWriter()

    for i in range(input_pdf.getNumPages()):
        pdf_page = input_pdf.getPage(i)
        pdf_page.mergePage(watermark_page)
        output.addPage(pdf_page)

    with open(merged, "wb") as merged_file:
        output.write(merged_file)
```
The code will put a watermark on all pages within the PDF.

That's all. Keep coding.
osquery – SQL powered operating system instrumentation, monitoring, and analytics framework
Tags: monitoring, security, sql, framework
Published: 2021-04-08 07:44:09

osquery exposes an operating system as a high-performance relational database. This allows you to write SQL-based queries to explore operating system data. With osquery, SQL tables represent abstract concepts such as running processes, loaded kernel modules, open network connections, browser plugins, hardware events or file hashes.

[osquery](https://kali-linuxtr.net/osquery-sql-powered-operating-system-instrumentation-monitoring-and-analytics-framework)
Do you code mobile-first?
Tags: discuss, webdev, coding, css
Published: 2021-04-08 07:30:12

---
title: Do you code mobile-first?
published: true
description: 
tags: discuss, webdev, coding, css
cover_image: https://www.moneythor.com/wp-content/uploads/2013/04/balance.jpg
---
According to [Statcounter](https://gs.statcounter.com/platform-market-share/desktop-mobile-tablet), the device market share in 2021 Q1 is:

54.25% - Mobile
42.9% - Desktop
2.85% - Tablet

What is your preferred dev workflow?
Do you code mobile-first? Or do you design for desktop and then work on responsiveness for the mobile afterward?
WordPress Scheduled Backups by Your Hosting Provider
Tags: wordpress, tutorial, help, webdev
Published: 2021-04-08 07:20:19


<h2>Site Ground</h2>
On the Security > Backups page on my SiteGround dashboard, you can see every backup which has automatically taken place–in my case they’re scheduled to happen every afternoon. At the top of the page, I can also trigger a manual backup if I need one right now.
![Site Ground](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k5112vyd0lk5eybgabqc.png)
For each of these backups, I have the option to restore:

<ul><li>all files and databases</li><li>files</li><li>databases</li><li>email</li></ul>

Automated backups like this are definitely a feature which you should look for when choosing a WordPress web host.

<h2>WP Engine</h2>
All backup functionality takes place from the same page in your User Portal, called “Backup Points”. To access the Backup Points page:
![WP Engine](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uo0u4sssu3ubmye0iaw3.png)
Log in to the User Portal

Select the environment name

Click Backup Points

Restore (or rollback) your website to a previous version:

Open  in the Backup Points User Portal

Select a backup from the list by clicking the radio button

Backup is in server time UTC

Click Restore
Do you use Magic links?
Tags: discuss, webdev, security
Published: 2021-04-08 07:07:06

---
title: Do you use Magic links?
published: true
description: 
tags: discuss, webdev, security
cover_image: https://ps.w.org/passwordless-login/assets/banner-772x250.png?rev=2190567
---
Magic links are passwordless auth methods, that generate unique access links. These are usually valid for a short period of time and normally sent to the email you provide in the login step. 

Personally, I'm not a huge fan, and I prefer to login with social accounts, as it's way easier than opening an email each time.  

What is your experience with these? Do you use them?
RASA - REST API
Tags: rasa, chatbot, nlp, ai
Published: 2021-04-08 07:00:48

So far, we have been interacting with the chatbot in the terminal.

In this chapter, we will look at how we can send messages to the chatbot via REST API.

Add the following to the `credentials.yml`. If you created your project using `rasa init`, it should be already there and you don't need to do anything.

```yml
rest:
  # you don't need to provide anything here - this channel doesn't
  # require any credentials
```

To send a request, I will use [Postman's](https://www.postman.com/) desktop app. You can now run Postman also in the browser without installing the app. Or you can use [https://hoppscotch.io/](https://hoppscotch.io/). You can of course use terminal interface like [curl](https://curl.se/) as well.

Let's start the server by running `rasa run`.
The server is now running on `http://localhost:5005/`.

![Server is running](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g5y5n7xwtczuuoncmhip.png)

Now, send a POST request to `http://localhost:5005/webhooks/rest/webhook` in the following format:
```json
{
  "sender": "test_user",
  "message": "Hi there!",
}
```

The response will be a JSON body of chatbot responses, for example:
```json
[
    {
        "recipient_id": "test_user",
        "text": "Hey! How are you?"
    }
]
```

Here's how it looks in Postman:

<a href="https://www.loom.com/share/cd08c9d3209d460ca28c22030f4fdc9a"><img style="max-width:300px;" src="https://cdn.loom.com/sessions/thumbnails/cd08c9d3209d460ca28c22030f4fdc9a-with-play.gif"></a>

You can learn more about Rasa's REST API in the [documentation](https://rasa.com/docs/rasa/connectors/your-own-website#rest-channels).

In the next chapter, we will look at Rasa X, a tool for Conversation-Driven Development.

Repository for this tutorial:
{% github petr7555/rasa-dev-tutorial no-readme %}

You can checkout the state of the repository at the end of this tutorial by running:
```bash
git clone --branch 07-rest-api git@github.com:petr7555/rasa-dev-tutorial.git
```
Get the Right Start for a New Project with Project Initiation Checklist
Published: 2021-04-08 06:54:35



Project Management Software

Kickstarting a new project is a challenging task because it decides the success of your project. Before project initiation checklist, you need to consider various aspects ranging from preparing the scope to estimating the costs and delegating tasks to create a defining timeline. Simply put, all the key performance indicators (KPIs) need to be considered before initiating the project. 

Without making a framework for initiating the project, it is possible that all the necessary tasks remain pending. Let’s go through the key reasons why we should make a project initiation checklist. These reasons apply to the project initiation using either waterfall methodology or agile approach. 

Key Reasons Why You Need Project Initiation Checklist
Creating a checklist for project initiation can establish a strong foundation for successful project completion. Here are the key benefits of a project initiation checklist-

– It acts as a project charter that the project manager can use to keep all the team members and stakeholders on the same page during and after project initiation

– It can reduce the chances of miscommunication significantly and enable the team to ensure that all the necessary tasks are fulfilled on time while meeting expectations

– Project objectives are set at the initiation phase that assists the company to minimize operational costs and maximizing the benefits while delivering the real value

While creating a project initiation checklist, three factors are considered- they are capacity, team capability, and stakeholders. It is fair to mention that a project stands on three legs- time, quality, and cost. It is necessary to consider these three aspects to ensure successful project accomplishment.  

After going through the importance of the project initiation checklist, we will dig deep into aspects that you should consider including in the list. In other words, we will look at the objectives of the project initiation phase.

Original Source: Get the Right Start for a New Project with Project Initiation Checklist