Using Socket.io with Node.js

Currently, I am incorporating socket.io within a NodeJS application. The socket.io page can be accessed at localhost:8081/socket.io/. However, my goal is to have it located at localhost:8081/hola/socket.io/. Is this achievable?

var express = require("express");
var app = express();
var server = require("http").Server(app);
var io = require("socket.io")(server);
//some code here...
server.listen(8081, function() {
    console.log("Server running at http://localhost:8081/");
});

Answer №1

To specify the path for socket.io, simply include a path attribute in the options object when initializing it:

var io = require("socket.io")(server, { path: '/hello/socket.io'});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

An error was encountered while trying to locate the "favicon.ico" in Node Express

Whenever I attempt to download an image through a URL passed as a query string using Express, I keep encountering the error message Error: Invalid URI "favicon.ico". Is there a way to prevent my browser from constantly requesting for a favicon? I am utiliz ...

Display index.html regardless of where it is located

I have a Node.js app using Express and I want the index.html file to be displayed to the user regardless of the URL they are on. For example, if someone goes to http://example.com, they should see the same page as if they went to http://example.com/test. ...

Troubleshooting: Express router does not correctly implement Mongoose's findByID method when using URL route

After following a tutorial, I encountered an issue with the code: /* GET one item. */ router.get('/items/:id', (req, res) => { Item.findById(req.param.id, (err, items) => { if (err) res.status(500).send(error) res.status(200).js ...

In NodeJS, many middleware must be installed individually, such as bodyParser

While attempting to set up my application, which employs multiple middlewares including body-parser, I encountered the following error: Error: Most middleware (like bodyParser) is no longer bundled with Express and must be installed separately. Please ...

Error: The module you are trying to import from the package is not found. Please check the package path and make sure that

I encountered an issue when trying to compile a code in Reactjs. As a beginner in Reactjs, I'm struggling with this. Module not found: Error: Package path ./cjs/react.development is not exported from package /Users/mansi/letsgrowmore/to-do-list/my-rea ...

Guide on importing an ES6 package into an Express Typescript Project that is being utilized by a Vite React package

My goal is to efficiently share zod models and JS functions between the backend (Express & TS) and frontend (Vite React) using a shared library stored on a gcloud npm repository. Although the shared library works flawlessly on the frontend, I continue to e ...

Thinkster's MEAN Stack Tutorial experiences a 404 error when attempting to make an API

I'm currently following a tutorial from Thinkster that demonstrates how to create a reddit-like web application using the MEAN stack. As part of the tutorial, it advises utilizing the curl command to generate a new post. C:\root>curl --dat ...

Node.js encountered a TypeError because it was unable to read properties of null while trying to access the 'matches' attribute

When I attempt to run npm install canvas png-js date-fns axios crypto-js ts-md5 tslib @types/node dotenv typescript fs require tslib prettytable jsdom tough-cookie <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="73040033445d475d ...

Which token is required by an iOS application to authenticate user-related requests with a RESTful API?

As a beginner in iOS and RESTful API development, I have successfully created a local API in Node.js that communicates with a local MongoDB instance. Currently, I am implementing user authentication using Sign in With Apple, following a helpful tutorial fr ...

Tips for saving an array from the server into a script variable

I'm currently working with the express js framework along with Handlebarsjs as the templating engine. My aim is to pass an array from the router to the view, and then store this array within a script tag. //users is an array res.render('chatRoom ...

Having trouble installing Cordova Ionic through npm

Is there a solution to resolve this issue? C:\WINDOWS\system32>npm install -g cordova ionic npm ERR! code E404 npm ERR! 404 Not Found: pinkie-promise@^2.0.0 npm ERR! For more details, check the following log: npm ERR! C:\Users\ ...

Installation using npm stalls in a Docker container

I encountered an issue while trying to launch my react docker container (https://github.com/AndrewRPorter/flask-react-nginx). The installation process stalls after displaying multiple warnings. The OS I am using is Ubuntu. It seems like there might be som ...

Node:alpine-lts Docker Build has inexplicably stopped functioning

After implementing my Dockerfile FROM node:lts-alpine as node ARG STAGE='dev' ARG STAGEPATH='/dev' WORKDIR /app COPY package*.json ./ RUN npm install COPY . . RUN $(npm bin)/ng build --configuration $STAGE --base-href=${STAGEPATH}/konne ...

Error message "Unable to locate the specified file or directory" when trying to install application on Android device through node_modules in React Native

After creating my new project in React Native, I attempted to run the Android app using the command npm run android However, I encountered several issues which I am unable to pinpoint: /Users/.../ProjectName/node_modules/.bin/launchPackager.command ; exit ...

Having trouble with Nodejs Express failing to load script files?

I am attempting to launch an Angular application through node-express. 1 File Structure AngularNode public /core.js /index.html project.json server.js 2 server.js var express = require('express'); var app = expres ...

NPM installation fails with a 'connection refused' error

Every time I attempt to use npm to install a package, it crashes without fail. This is the error message that keeps popping up: 0 info it worked if it ends with ok 1 verbose cli [ 'C:\\Program Files\\nodejs\\node.exe&ap ...

PhantomJS Karma encountering SyntaxError when trying to export variables

I've encountered an issue while running Karma and PhantomJS. When I attempt to run, the console displays the following message: 22 03 2016 14:58:47.865:WARN [karma]: No captured browser, open http://localhost:9876/ 22 03 2016 14:58:47.875:INFO [karm ...

NPM attempts to retrieve a dependency that has not been specifically requested

When I ran the command npm install, an error occurred: npm ERR! code ETARGET npm ERR! notarget No matching version found for duplexer2@^0.2.0 npm ERR! notarget In most cases you or one of your dependencies are requesting npm ERR! notarget a package versio ...

Perform a JSON POST request from an HTML script to a Node.JS application hosted on a different domain

In an attempt to send string data via a post json request using JavaScript within an .erb.html file, I am facing the challenge of sending it to a node.js app on another domain that uses express to handle incoming requests. After researching online, I have ...

Upon installation, swagger may generate a notification about a dependency concern

My attempt to install Swagger via npm using this link is being met with a warning message as shown below- npm WARN <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="31424650565654431c1c5e585555">[email protected]</a> ...