The phrase 'nodemon' is not identified as a valid cmdlet, function, script file, or executable program

Recently I started working with Node.js, but I encountered an error when trying to run a program. The error message says "the term nodemon is not recognized the name of cmdlet, function, script file or operable function". Can someone please assist me with this?

index.js

 // This is a Node server which will handle socket io
    // If a new user is joined then socket.io fires
    
    const io = require('socket.io')(7000)
    
    const users = {};
    
    io.on('connection', socket => {
        socket.on('new-user-joined', name => {
            users[socket.id] = name;
            socket.broadcast.emit('user-joined', name)
        });
    
        socket.on('send', message => {
            socket.broadcast.emit('receive', { message: message, name: users[socket.id] })
        });
    
        socket.on('disconnect', message => {
            socket.broadcast.emit('left', users[socket.id]);
            delete users[socket.id];
        });
    });  
    

client.js

This is my client file where I define all the tasks like where messages should be sent and received.

 const socket = io('http://localhost:7000');
    
    const form = document.getElementById('send-container');
    const messageInput = document.getElementById('messageInp');
    const messageContainer = document.querySelector('.container');
    
    var audio = new Audio('whistle.mp3');
    
    const append = (message, position) => {
        const messageElement = document.createElement('div')
        messageElement.innerText = message;
        messageElement.classList.add('message');
        messageElement.classList.add(position);
        messageContainer.append(messageElement);
        if(position =='left') {
            audio.play();
        }
    }
    
    const name = prompt("Enter Your Name to join");
    socket.emit('new-user-joined', name)
    
    socket.on('user-joined', name => {
        append(`${name} joined the chat`, 'right');
    })
    
    socket.on('receive', data => {
        append(`${data.name}: ${data.message}`, 'left');
    })
    
    socket.on('left', name => {
        append(`${name}: left the chat`, 'right');
    })
    
    form.addEventListener('submit', (e) => {
        e.preventDefault();
        const message = messageInput.value;
        append(`You: ${message}`, 'right');
        socket.emit('send', message);
        messageInput.value = '';
    })
    

Answer №1

If you want to set up nodemon for a specific project, follow these steps:

  1. npm init -y

This command will generate a package.json file in the project's main directory.

  1. npm install nodemon

  2. In the package.json file, navigate to the scripts section and add the following line:

Make sure to include the following script:

"server" : "nodemon server.js"

Save the package.json file once you have made the necessary changes.

Next, open your terminal and run the following command:

npm run server

Nodemon will now be up and running, keeping track of any changes you make to your files.

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

Determine the number of input files in HTML5 when there is a change

I am working on a project that requires using the HTML5 File API to determine the number of files selected in an input file element and then displaying this count in another element. Here is the HTML code: <div class="form-row"> <label>Ma ...

Adjust the canvas size to fit its parent element ion-grid

I am currently working on an Ionic 3 component that displays a grid of images connected by a canvas overlay. I have utilized Ionic's ion-grid, but I am facing an issue with resizing the canvas. The problem is that I cannot determine the correct dimens ...

The function _path2.default.basename does not work when using convertapi within an Angular framework

I'm currently working on integrating the convertapi into my Angular 11 application by referencing the following documentation https://www.npmjs.com/package/convertapi My goal is to convert PDFs into images, However, I encountered an issue when tryi ...

Hide the element, update its content, and smoothly transition back

I am looking to add dynamic content to an element on my HTML page, with the inserted HTML transitioning smoothly from 0% to 100% opacity. HTML <div id="content"></div> CSS #content { opacity: 1; transition: opacity .5s ease-out; -moz ...

Automatically navigate through form fields using jQuery when pasting data

Enhancing the form filling experience by allowing users to prepare a text file in advance and simply copy/paste it into the form for quick submission. Integration of a feature that automatically moves to the next input field when a tab or newline character ...

Error occurred during npm build with Browserify: Module not found

When I run npm build with the following command: "build": "browserify -t [ babelify --presets [ es2015 react ] ] app/assets/app.jsx -o public/javascripts/app.js" I encounter the error message below: Error: Cannot find module 'components/maininput.j ...

Only referring to a CSS class within a particular element

I have defined the following CSS: .grade a{ color: white; } It is working, but maybe too well... Now, I have an HTML structure like this: <li class="grade"> <a><i class="fa fa-star fa-fw"></i></a> My Text < ...

Difficulty in establishing a handshake within an ExpressJS Node application due to Let's Encrypt SSL certificate issues

I'm currently facing an issue while configuring a node server with Let's Encrypt certificates. I am utilizing Express to create an HTTPS server as shown below: var fs = require('fs'); var app = require('express')(); var https ...

The presence of CSS rollovers on a scrollable div is causing overflow problems

Currently, I am developing an interface that involves a list of items inside a scrollable div. Some of these items have rollover menus that extend beyond the boundaries of the div when hovered over. It is crucial for the website to be compatible with disab ...

Using MongoDB to restrict fields and slice the projection simultaneously

I have a User object with the following details: { "_id" : ObjectId("someId"), "name" : "Bob", "password" : "fakePassword", "follower" : [...], "following" : [..] } My goal is to paginate over the follower list using the slice projection operat ...

I am having trouble resolving 'otp-input-react' in my project directory at D:projectappsrc

I have been troubleshooting this issue but haven't been able to find a solution yet. I even tried uninstalling and reinstalling the package, but it still isn't working as expected. Here are some images for better clarity: https://i.stack.imgur.c ...

The object persists in revealing the password that I am attempting to conceal

Seeking help to hide the password object from being displayed. Below is my code snippet where I am using bcrypt to hash the password. Even though I am trying to hide the return object, I am not seeing the desired outcome. Can someone please point out wha ...

Can the same form be submitted with two different actions?

I am facing an issue with a form that is supposed to submit data to 2 different pages using the POST method. After trying some javascript code, I found that one form submission works correctly while the other does not. <form id="add"> <input ...

AJAX successfully completes, but no response is received

I've been struggling to get the success function in my AJAX call to trigger. I know everything is set up correctly because when I make a request to my API, I can see that it's hitting the URL and the server is responding with an HTTP 200 status. ...

When utilizing Xpath, it consistently triggers the Python <li> element as the first child

I am attempting to click on multiple links with the following code: self.browser.find_element_by_xpath("//li[@onclick[contains(text(),"+origin_iata_code+")]]").click() The origing_iata_code is from this list: ['FLL', 'MCO', 'AFL ...

React is having trouble resolving the path required

Having an issue with the tracking-js library in my project. I'm using React and despite checking my package.json and confirming that the module is installed, I keep receiving errors indicating that the module cannot be found. This is how I am attempti ...

Create a regular expression in Javascript that only matches strings that do not contain any periods

Struggling with setting up an express route for localhost:3000/test and utilizing regex to handle specific URL patterns. Need assistance combining regex with Express params functionality. router.get('/test/:path[\s^.]*$', function () { ...

What is the best way to position my div outside of the wrapper while keeping the text inside?

For example: https://i.sstatic.net/UyhOl.png I want the blue text that says "join our discord server" to extend to 100% width when it's placed inside the wrapper. The reason it's inside the wrapper is to ensure the text matches up perfectly with ...

The backend is serving HTML content, but the frontend is not initiating any redirects

After hitting an API endpoint and examining the network call responses, I identified that the HTML response returned with a status code of 302. Despite this, I am perplexed as I do not witness the expected redirect on the user interface. The intended redir ...

When a condition fails, the default style in the CSS media query does not apply

Whenever the user resizes the browser, my media query for max-width kicks in to make the design responsive. But I'm facing an issue where when the user returns back to the original browser size, the design is still a little messed up and doesn't ...