r/javascript • u/DanielRosenwasser • 21h ago
r/javascript • u/jhnam88 • 10h ago
TTSC: TypeScript v7 Runtime (ts-node alternative) + unplugin for every bundlers
github.comr/javascript • u/AutoModerator • 8h ago
Showoff Saturday Showoff Saturday (December 05, 2026)
Did you find or create something cool this week in javascript?
Show us here!
r/javascript • u/Accurate-Issue-6686 • 17h ago
I Made An Open-Source Cross-Platform Music Player
github.comr/javascript • u/ClickOk5811 • 35m ago
AskJS [AskJS] Reading the last line of a file when it has no trailing newline
A common mistake in Node.js is splitting file content by "\n" and assuming every line ends with a newline. If the last line does not, split("\n") still returns it as a final element, but code that iterates with readline() or relies on endsWith("\n") can silently drop or mishandle it.
The before:
const fs = require("fs");
const content = fs.readFileSync("data.txt", "utf-8");
const lines = content.split("\n");
for (const line of lines) {
console.log(line);
}If data.txt ends without a newline, the last line is still there, but any logic that expects a trailing newline on every element — or that filters out empty strings assuming they are artifacts — can behave inconsistently across files.
The after: trim only the final newline if present, then split:
const fs = require("fs");
let content = fs.readFileSync("data.txt", "utf-8");
if (content.endsWith("\n")) {
content = content.slice(0, -1);
}
const lines = content.split("\n");
for (const line of lines) {
console.log(line);
}This works the same whether the file ends with \n, \r\n, or nothing at all. For \r\n handling, normalize first:
content = content.replace(/\r\n/g, "\n");One edge case: an empty file returns [""] after splitting, which is usually not what you want. Guard with content.length === 0.
Question: Do you handle the no-trailing-newline case explicitly in your file-reading code, or do you assume inputs always end with a newline?
r/javascript • u/xNewLevel • 17h ago
Njectify - Customize any website with CSS and JavaScript
chromewebstore.google.comHello guys, hope it's okay to share my extension here!
I developed Njectify to give users more control over their browsing experience.
You can customize website layouts, remove annoying elements, automate repetitive tasks, add new functionality, and improve existing interfaces using custom JavaScript and CSS.
Everything is saved and automatically applied whenever you revisit a website.
It already has over 70 users, and I'd love to hear your feedback!
Available on the Chrome Web Store!
I really appreciate your feedbacks!
r/javascript • u/soft-boy1234 • 21h ago
SF Laser Taxi – a multiplayer waymo laser tag game
sflasertaxi.comSF Laser Taxi is a multiplayer browser game where you drive a robotaxi around a small San Francisco and shoot lasers at the other players. There's no install and no account: pick a name and you're in.
Controls are WASD to drive, Space to fire and Shift to boost. Your score is how many taxis you've tagged since you last died, and the high score board keeps each name's best single life. There are 5 bots always driving around, so there's something to shoot at even when nobody else is online.
How it's built:
- The frontend is Babylon.js with plain ES modules, so there's no bundler and no build step. The textures, models and sky are CC0 assets from Poly Haven.
- The backend is one Node WebSocket server whose only dependency is ws. It sends position snapshots 20 times a second and owns HP, kills and deaths.
- Each client moves its own car and reports its own laser hits. The server rejects a hit if there was no recent shot, the target is too far away, or the target just respawned. That's enough for a game with no stakes, but it isn't cheat-proof.
- The city is generated from a seeded RNG, so every client gets the same buildings and laser collisions agree without the server ever sending a map.
- Phones get a lighter three.js renderer, because the HD scene was too heavy for mobile Safari. Both renderers use the same protocol, so phone and desktop players are in the same game.
The code is MIT licensed: https://github.com/bortpro/WaymoWorld
A tip: on desktop, type "starman" while you're driving. Your taxi turns into a flying roadster. Z and X fire the left and right thrusters, both together lift you, and you can land on rooftops.
I'd like to hear how the netcode feels on your connection, and what you'd add next.