Read issue #1 of Daily Digest, by Mailbrew Team.
24
Friday May, 2024
Does minifying node.js code increase execution speed?

Javascript is naturally an interpreted languge, so will minifying a js file will increase execution speed? My take on it is that the file reader can skip spaces and new lines and therefore interpret the code faster compared to a unminified js file.

Is there an easy way to debug this? If I could isolate what file the build was failing on it would help a lot!

Is there an easy way to debug this? If I could isolate what file the build was failing on it would help a lot!

Strong vs WeakRef #coding #javascript #nodejs

Strong vs WeakRef #coding #javascript #nodejs

Authenticaion/Authorization for a small/medium project?

Just as the title states...I'm beginning work on a new project this weekend that will require a user to login to be able to do -some- stuff within it. My question is...for a project that's really not going to be very large...what's the best method of handling authentication/authorization to protect both VueJS client-side routes and the server-side Express API that I'll be using to store data? I've seen numerous solutions, but these are the three that stood out, not sure if any of them would be considered overkill? PassportJS (storing users in a Mongo instance, then maybe allowing login via FB/Google if I can figure those out?) Okta/Auth0 * Amazon Cognito It's seeming like maybe just using Passport would be the easiest thing to do in this scenario even if it's a bit more "work" to manage the storing of users/passwords myself? I've been toying with Okta but been frustrated with trying to do various things? Figured I'd get opinions here and go from there, because it seems like I should figure out the login system first before working on the rest of the project.

Getting an error in my Application can't figure out what it is

SingleMovieComponent.js import axios from 'axios'; import { useEffect, useState } from 'react'; import { AiFillLike } from "react-icons/ai"; import { Container, Row, Col, Image, Button, InputGroup, FormControl } from 'react-bootstrap'; //import { faCoffee } from '@fortawesome/free-solid-svg-icons' import { useNavigate, useParams } from 'react-router-dom'; function SingleMovieComponent() {     const navigate = useNavigate()     const params = useParams()     var [movie, setMovie] = useState({})     var [like, setLike] = useState(false)     var [comment, setComment] = useState("")     useEffect(() => {         const { id } = params         axios.get(&gravehttp://localhost:3001/api/movie/${id}&grave)             .then(res => setMovie(res.data))             .catch(err => console.log(err))     })     async function handleLike(id) {         const token = localStorage.getItem("token")         console.log(token)         if (token) { …

Organization suggestions for a small-scale full-stack project? I'm a new(-ish) dev!

Greetings, fellow developers! I'm a hobbyist Node dev and I'm going to be starting on a new project this weekend -- it'll be a full-stack thing, using Vue for the front-end and Express for the backend w/ Mongoose/etc. I have a few questions: 1) When you're doing something like this, is it best to have the two "halves" of the project be separated? (Would be separate git repositories, etc.) I've read that's a good idea for smaller projects (like this one), but figured I'd ask. I've seen examples of the front-end and back-end completely separate, but then I've also seen examples of React/Vue frontends being served BY the Express server itself. This has always confused me. 2) If the halves -are- separated, is it at all worth using a bundler like Rollup/Webpack or whatever to build the Express part of the application? Obviously if I'm using Vue, it'll be using Vite by default so that should be easy to figure out for deployment EVENTUALLY, but I'm not even close to that yet. All in all, I'm trying to figure out what best practices are when I'm getting started as opposed to making bad decisions now and shooting myself in the foot and wishing that I could reorganize things later on. Thanks in advance to anyone who can offer some guidance!

Check out node-promptgen: A Simple Tool to Generate AI Prompts for Software Projects

Hey folks, Just wanted to share a little project I whipped up called node-promptgen. It’s a super simple command-line tool for projects that helps you generate prompts for AI analysis. I made it to streamline the process of extracting code snippets and project structure for use with AI language models like ChatGPT. What it does: • Extracts code snippets from your project directory. • Ignores unnecessary directories like node_modules and .git. You can ignore additional files/folder • Extracts project folder structure and includes it in the prompt. • Lists dependencies from package.json. • Optionally adds a basic boilerplate explainer prompt. Feel free to contribute! https://github.com/mkkurt/node-promptgen

NodeJS Docs in VSCode not working

Hello everbody, Im pretty new to VSCode in generell so I hope this isnt some rookie mistake but I couldnt find anythiny myself. Im currently learning Javascript with the NodeJS Runtime and I run into an issue with my debian machine. When I use NodeJS on my Windows machine, I can see the documentation of Node functions when I hover over them. For Example: http.createServer(); When I hover over createServer(), it shows me the input parameters and also auto completes. However, on my Debian Machine this doesnt work. It just shows "any". I installed NodeJS via nvm and everything works perfect when I execute it but I find the docs in VSCode really usefull. I already tried adding a jsconfig.json file. I got the feeling I have to install something additional to NodeJS on Linux to get the docs.

nodejs && <img src="xxx"> Video playback suddenly stops after a few seconds

backend code ​ const express = require("express"); const path = require("path"); const ffmpeg = require("fluent-ffmpeg"); const app = express(); const videoPath = path.join(__dirname, "static/test2.mp4"); let interval = null; app.get("/video", (req, res) => { const clientAddress = req.connection.remoteAddress; const clientPort = req.connection.remotePort; console.log(&graveClient connected from ${clientAddress}:${clientPort}&grave); res.writeHead(200, { 'Content-Type': 'multipart/x-mixed-replace; boundary=frame', 'Connection': 'keep-alive', 'Pragma': 'no-cache', 'Cache-Control': 'no-cache' }); let frameQueue = []; let videoProcessFinish = false; const command = ffmpeg(videoPath) .format("image2pipe") .videoCodec("mjpeg") .outputOptions([ "-vf", "fps=24", "-q:v", "2", ]) .on("error", (err) => { console.error("Error: " + err.message); // res.end(); }) .on("end", () => { console.log("Video processing finished."); videoProcessFinish = true; sendFrames(); }) .pipe(); command.on("data", (frame) => { frameQueue.push(frame); }); function sendFrames() { frameQueue = frameQueue.filter(frame => frame.length > 0); interval = setInterval(() => { if (frameQueue.length > 0) { const frame = frameQueue.shift(); res.write(&grave--frame\r\nContent-Type: image/jpeg\r\n\r\n&grave); res.write(frame); console.log("Frame sent, queue length:", frameQueue.length); } if (frameQueue.length === 0 && videoProcessFinish) { clearInterval(interval); console.log("All frames sent, ending response."); res.end(); } }, 50); } req.on("close", () => { console.log(&graveClient disconnected from ${clientAddress}:${clientPort}&grave); // if (command) { // command.kill('SIGSTOP'); // } if (interval) { clearInterval(interval); } }); }); app.listen(3000, () => { console.log("Server is running on http://localhost:3000"); }); frontend code ​ <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <img id="videoFeed" class="img-fluid" src="http://localhost:3000/video" style="height: 100%;width: 100%;object-fit: fill;" alt="Video Stream"> </body> </html> result screen record The video is one minute long but only plays for 1 second question * Why does the page stop playing after 1 to 2 seconds of video playback, and the webpage becomes blank, but the link is not broken and data is still being sent?

MERN stack using vite, redux toolkit and jwt. Cors errors when its time to deploy my app on render.com

Greetings! So I am able to finish my first ever ecommerce app using MERN stack, vite, JWT for authentication and redux toolkit for handling my frontend. Before deploying it, I make sure that all of the features are working perfectly as expected. But when it time to deploy it in render.com, I encountered a lot of errors mostly related to cors. Some of my api calls is working such as GET products to be displayed in the home page. And I can log in or register and my JWT is generating. The rest is a bunch of errors, my JWT wont generate token anymore if I want to send a product review, or in my admin account, I cant add, edit or remove a product. I double checked my application locally and its indeed there is no error. app.use(cors({     origin: ALLOWEDORIGIN,     credentials: true,     methods: ['GET', 'POST', 'PUT', 'DELETE'],     allowedHeaders: ['Origin', 'Content-Type', 'Accept', 'Authorization', 'X-Request-With', 'Access-Control-Allow-Origin'], })); This is my CORS code in server.js import express from "express"; const router = express.Router(); import {      getProducts,      getProductsById,      createProduct,      updateProduct,      deleteProduct,      createProductReview,      getTopProducts     } from "../controllers/productControllers.js"; import {protect, admin} from '../middleware/authMiddleware.js'; router.route('/').get(getProducts).post(protect, admin, createProduct); router.get('/top', getTopProducts) router.route('/:id').get(getProductsById).put(protect, admin, updateProduct).delete(protect, admin, deleteProduct); router.route('/:id/reviews').post(protect, createProductReview); export default router; >productRoutes.js import asyncHandler from "../middleware/asyncHandler.js" import { protect } from "../middleware/authMiddleware.js"; import Product from "../models/productModel.js"; //@desc Fetch all product //@route GET /api/products //@access Public const getProducts = asyncHandler(async (req, res) => {     const pageSize = 8;     const page = Number(req.query.pageNumber) || 1;     const keyword = req.query.keyword ? { name: { $regex: req.query.keyword, $options: 'i' } } : {};     const count = await Product.countDocuments({...keyword});     const products = await Product.find({...keyword})     .limit(pageSize)     .skip(pageSize * (page - 1));   …

Twitter, RSS, YouTube, Newsletters, Weather, Calendar, ...

You can customize this digest to include all the sites and sources you want.