/r/node
works fine on localhost :d (as always happens) but on production when i use domain it does not send cookies to browser.
my domains are :
https://xxxxapi.thetetrobyte.com
https://xxxxfront.thetetrobyte.com
Per a redditor's request, I have extracted my boilerplate for a full-stack next
repo, with typed contracts from the database to the front-end.
The template uses a separate API to unlock next
's caching features and circumvent the limitations of next
for backend code. It also demonstrates using minimalist express
-like patterns but typed (via fastify
+ zod
) instead of relying on maximalist solutions like NestJS.
https://github.com/chriskuech/fullstack-monorepo-template
Let me know your thoughts or if there's anything else you'd like to see.
I would like to publish a Python library that acts as a wrapper to a Typescript library. I don't want to rewrite the whole library in Python and have to worry about feature parity! What approaches would you reccommend?
Hey everyone,
I’m getting started with Node.js for backend development and I’m looking for some project ideas that can help me get a better grasp of things like RESTful APIs, working with databases, authentication, and other core concepts.
How possible is for someone beginner to get his first programming job as backend developer without knowing frontend technologies? What is the best study path in this case? For example someone who hates css and don't want to spend time to learn it. PS: I mean backend developer preferably using JavaScript (for example node.js)
I'm trying to create a real-time streaming output of a shell script execution using Bun and Hono. Currently, the output is buffered and only shows up all at once when the script finishes, but I need it to stream in real-time as the script produces output.
Shell Script (deploy-container.sh
):
#!/bin/bash
# Script that deploys a container and shows progress
echo "🚀 Starting deployment process..."
echo " → Deploying Docker container..."
# ... more echo statements and actual deployment logic
echo "✅ Deployed successfully!"
Current Implementation:
(deploy.ts
):
import { $ } from "bun";
export const runDeployment = async (
imageName: string,
subDomain: string,
port: number
) => {
try {
const res =
await $`echo ${process.env.SYSTEM_PASSWORD} | sudo -S deploy-container.sh ${imageName} ${subDomain} ${port}`;
return res.stdout.toString();
} catch (e) {
console.error("Error running deployment:", e);
throw {
success: false,
error: e,
};
}
};
(index.ts
):
import { stream } from "hono/streaming";
import { runDeployment } from "../lib/deploy";
app.post("/deployContainer/:repoName", async (c) => {
try {
const repoName = c.req.param("repoName");
const imageName = `${repoName}:latest`;
const port = generateRandomPort();
const subDomain = generateSubdomain(repoName);
const deployData = runDeployment(imageName, subDomain, port);
return stream(c, async (clientStream) => {
const heartbeat = setInterval(async () => {
try {
await clientStream.write(" ");
} catch (err) {
console.error("Heartbeat failed:", err);
}
}, 1000);
try {
const res = await deployData;
clientStream.writeln(res);
} catch (error) {
console.error("Error deploying container:", error);
clientStream.write(`Error deploying container: ${error}\n`);
} finally {
clearInterval(heartbeat);
}
});
} catch (e) {
console.error(e);
return c.json({ success: false, error: e }, 500);
}
});
Current Behavior:
Expected Behavior:
Any help would be appreciated in getting the output to stream in real-time rather than being buffered until the end.
I’m currently looking for a new position as a Node.js developer. I have experience working with React, Node.js, Express, and MongoDB. If you’re hiring or know someone who is, please feel free to DM me or reach out at eveecloud99@gmail.com
So the idea is that I have a controller that asks an object in a model to make a document in the database. I have a middleware that triggers after an error is thrown in the controller. But if an error is thrown in the model then it is not caught by the errorHandeler. Now my question is if that is posible to do. I can catch the error in the model and then the server doesn't crash, however I don't know how to give the info about that to the frontend.
Now for some code. I will try to only show the things that matter.
module.exports.post_groep = async (req, res, next) => {
try {
if (req.body.naam == "") {
throw Error("Invalid field: naam");
}
const groep_id = await Groep.postGroep(db_naam, req.body);
res.json({ groep: groep_id });
} catch (err) {
return next(err);
}
};
Above is the controller, the first step within the process that matters.
const handleErrors = (err) => {
let errors = { naam: "", afdeling: "" };
console.log(err);
if (err.code === 11000) {
errors.naam = "Naam reeds ingebruik";
return errors;
}
if (err.message === "Invalid field: naam") {
errors.naam = "Gelieve het veld naam in te geven";
}
return errors;
};
const errHandler = (err, req, res, next) => {
const errors = handleErrors(err);
return res.status(400).json({ errors });
};
module.exports = errHandler;
This is obviously the errorhandler. I know for a fact that the thrown error("Invalid field: naam") works. I only need to get the err.code === 11000 to work for now.
class Groep {
static async postGroep(db, obj, next) {
try {
/*if (obj.naam == "") {
throw new Error("Invalid field: naam");
}*/
const validate = ajv.compile(schema);
const valid = validate(obj);
if (valid) {
return await connector.queryPoster(db, "groepen", obj, true);
}
} catch (err) {
/*console.error(err.code);*/
return next(err);
/*if (err.code == 11000) {
throw Error("Duplicate field offence");
}*/
}
}
As you can see is the connection to the database handled in the model and that works fine. The part commented out within the try block is just me testing it out, however that works only then I would have the same problem as I now have with the duplicate error. the return next(err) within the catch block does not work. I'd need to comment that out and uncomment the line above to make it work without handling the error. The last part also works but it doesn't get handled.
I'm rookie dev trying to install npm, and heard that I can get that by installing node JS. I went to the Node JS, however there are multiple options of downloading.
Should I install v23.5.0 (Current) or v22.12.0 (LTS)
Also, should I install it using fnm, docker, or chocolatey? For some reason it doesn't give me the option to select nvm or brew.
Any help would be appreciated
Edit: Theres also another option for x64, which is the prebuilt download option. Should I do that instead
Hi everyone. I'm playing with the Cluster module and just tried to "clusterize" my whole Node+Express app. My problem is: how do I create a singleton class (or equivalent) that all the forks can refer to and use? Must I use the messaging system that comes with the Cluster module or is there a different path? Any suggestion, doc or tutorial to read?
Hey,
I'm using a feature-based pattern in my boilerplate/starter kit, and I'm looking for reviews to improve it.
As far as I know, the feature-based pattern / folder structure is currently the best option for medium-sized companies.
What do you guys think about that?
https://github.com/ghostlexly/ultimate-expressjs-starter-kit
I"m able to install and use uWebsockets.js in my mac and it works fine but for some reason It won't work in docker I've tried with node, alpine and slim images, bun, npm, pnpm and yarn, but all of them just create an empty uWebsockets.js directory in node_modules, and I errors because typescript compiler can't find it, I've checked docker files without any imports, it's not there. Not sure why.
I was unable to find much on this while trying to troubleshoot for hours, seems like some issues with binaries not being downloaded for correct platform. but I don't even get any error logs during installation.
This is my docker file
# Use Node.js base image
FROM node:20-slim
# Install build dependencies for uWebSockets.js
RUN apt-get update && \
apt-get install -y \
build-essential \
python3 \
&& rm -rf /var/lib/apt/lists/*
# Create app directory
WORKDIR /usr/src/app
# Copy package files
COPY package*.json ./
# Install dependencies
RUN npm install
# Copy source code
COPY . .
# Compile TypeScript
RUN npm install -g typescript && \
tsc
# Expose the WebSocket port
EXPOSE 9001
# Start the server
CMD ["node", "dist/server.js"]
package.json dependency
"dependencies": {
"uWebSockets.js": "github:uNetworking/uWebSockets.js#v20.51.0"
},
I am a Node.js backend developer trying to get a job in the backend domain. How can I stand out from the crowd? I would love your suggestions, guys. I know Node.js, Express, authentication, authorization, JWT, and MongoDB, and I can build REST APIs. I am currently learning NestJS and can build REST APIs with it as well. What else can I do? I am targeting the next 2-3 months to get a job. I graduated in 2023 and am still jobless. u/srini53168
Complete noob here. I am learning node.js following some tutorials and they use this code:
const express = require('express');
const path = require('path');
// Create an Express application
const app = express();
// Define a route to serve the HTML file
app.get('/', (req, res) => {
// Send the HTML file as the response
res.sendFile(__dirname + '/index.html');
});
// Start the server
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(`Server is
running on port ${PORT}`);
});
But it appears that "require" is getting obsolete in favor of "import" modules. I am trying to do a basic res.sendFile but I am unable to do it.
Could you point me out to a tutorial that will help me with it?
Thanks in advance
I’m building a WhatsApp clone and working on the status feature, where statuses expire after 24 hours. Continuously checking for expired statuses for every user seems inefficient, even without making frequent API calls. What are some better approaches or backend solutions to handle this efficiently? Any advice or best practices would be greatly appreciated!
When you try { ... } catch (error) { ... }
this error
is always of type unknown
. The same for callbacks, when you hane someting like this:
someFunction(aParams, (data,err) => {
if(err) throw err
doSomething(data)
})
This err
is also typed unknown
. Is that because you can throw almost anything is JS ? What's the point of this feature by the way ? Does someone have an example of a situation where throwing something that is not an error was usefull ?
LDAP works fine and LDAPS works fine using the ldp tool on the server. Getting ECONNRESET 4077 error in the log file. Using Wireshark the traffic looks fine but of course I can't really tell what's going on because I haven't figured out a way to decrypt the LDAPS traffic yet. Anyone else seen this type of issues? The certificate on the domain controller is public certificate so I think trust is not an issue.
The project is designed for local use, with the server built using JS and the client in HTML and JS. I want to package the client into a web-view app to make it easier to use. However, I'm currently hardcoding the server IP in the client’s JS. If I change the server machine, the IP will change as well, and I won’t be able to update it in the app once it's packaged. What can i do to dont need to change the ip even if i change the server machine?
It's pretty standard to pack your README.md
file into your package, but what about CONTRIBUTING.md
? Is it just a waste of bytes to include, or is there value? Is there any value to your package consumers? Is there any value to third parties, like the NPM website?
I am using pgsql database for my Saas.
I use drizzle for my query but i didn't see the document of drizzle in detail about connection pool.
Dose drizzle handle release connection to pool auto after the query done (like client.release())?
if it is not, how to do that?
Thank you.