Errors and warnings caught off guard while running json-server with the --watch flag

I'm having some trouble using json-server in the following way:

$ json-server --watch db.json

Every time I try to run that command, I encounter errors or warnings depending on the version of json-server that is installed:

  • 1.0.0-alpha.1-1.0.0-alpha.12:

    sh: json-server: command not found
    

    or (if on Windows):

    The term 'json-server' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
    At line:1 char:1
    + json-server --watch db.json
    

    or (when executed via npx):

    npm ERR! could not determine executable to run
    
  • 1.0.0-alpha.13:

    node:internal/errors:496
        ErrorCaptureStackTrace(err);
        ^
    
    TypeError [ERR_PARSE_ARGS_UNKNOWN_OPTION]: Unknown option '--watch'. To specify a positional argument starting with a '-', place it at the end of the command after '--', as in '-- "--watch"
    
  • 1.0.0-alpha.14+:

    --watch/-w can be omitted, JSON Server 1+ watches for file changes by default
    
  • 1.0.0-alpha.13+, for users of Node.js versions prior to v18.3.0 and v16.17.0:

    import { parseArgs } from 'node:util';
             ^^^^^^^^^
    SyntaxError: The requested module 'node:util' does not provide an export named 'parseArgs'
    

Here's a simple package file (remember to update the version of json-server accordingly):

{
  "name": "q77787616",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "json-server --watch db.json"
  },
  "keywords": [],
  "license": "ISC",
  "dependencies": {
    "json-server": "1.0.0-alpha.12"
  }
}

Answer №1

json-server is currently undergoing active development towards reaching version 1. However, these alpha versions are being released on npm with the latest tag, causing them to be installed instead of the stable version (currently 0.17.4) when simply running npm install json-server. This has led to several issues:

  • Prior to version alpha.13, the correct binary was not installed at all, resulting in the inability to find the json-server command (typicode/json-server#1472).

  • With version alpha.13, the binary was included but the CLI changed, making --watch an invalid argument (typicode/json-server#1474):

    $ npx [email protected] --help
    Usage: json-server [options] <file>
    Options:
      -p, --port <port>  Port (default: 3000)
      -h, --host <host>  Host (default: localhost)
      -s, --static <dir> Static files directory (multiple allowed)
      --help  Show this message
    
  • Starting from version alpha.14, --watch is supported but not necessary, so the message has been reduced to a warning.

To check the version of json-server you have installed, use:

npm ls json-server

Due to the ongoing development and alpha status, it is recommended to explicitly install the stable version (the documentation can still be found here):

$ npm install json-server@0

Alternatively, if you wish to use alpha version 1 and are using a compatible Node.js version (i.e. ^16.17 || >=18.3), you can run npm install json-server@latest to get the latest version (make sure you have at least version alpha.14) and use the command without the --watch flag:

$ json-server db.json

Answer №2

To begin, confirm the version of the installed package. If you have version 1.0.0-alpha.23, there is no necessity to include --watch. Additionally, ensure that you generate the db.json document in the principal folder of your project. Upon completing this step, execute the subsequent command:

json-server db.json

Answer №3

Start by launching the "CMD" tool.

Next, run the command

npm install -g <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="19736a7677346a7c6b6f7c6b592937282e372d">[email protected]</a>
.

After that, enter the command json-server --watch db.json.

Find more information at: https://github.com/typicode/json-server/tree/v0

Answer №4

If you encounter issues with updating [email protected] within your current node_modules directory, the recommended steps are to delete the existing node_modules folder and then proceed with installing a stable version of json-server.

Type this command in your terminal: npm i <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="93f9e0fcfdbee0f6e1e5f6e1d3a3bda2a4bda7">[email protected]</a>

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

Whenever I navigate to a new page in my NEXTJS project, it loads an excessive number of modules

I am currently working on a small Next.js project and facing an issue where the initial load time is excessively long. Whenever I click on a link to navigate to a page like home/product/[slug], it takes around 12 seconds to load due to compiling over 2000 ...

Inserting duplicate rows from CSV using JavaScript

Currently, I am utilizing Papaparse to sum up rows with duplicate SKUs in my CSV file. I'm striving to achieve this task without the use of additional JS libraries such as D3. Here is a snippet of how my CSV data is structured: SKU,Daily total,Weekly ...

AJAX request made to a specific local directory, instead of the usual localhost

Currently, I am working on a project to create a database that can be filtered using various options. My approach was to keep it simple by using HTML for sliders and checkboxes, along with JavaScript/jQuery for filtering the results. This setup allows me t ...

Encountering a 422 ERROR while attempting to send a POST request

Below is the code snippet I am currently using: const url = new URL("https://api.chec.io/v1/products"); const headers = { "X-Authorization": `${process.env.NEXT_PUBLIC_CHEC_PUBLIC_KEY_SECRET}`, "Accept": "appl ...

What is the best way to show a nested div element within a v-for loop in Vue.js?

One interesting feature of my coding project is that I have an array nested within another array, and I iterate through them using two v-for loops. The challenge arises when I try to display a specific div in the second loop only upon clicking a button. ...

What is the best way to dynamically add a class to the right navigation element in Vue.js when the :class binding only accepts boolean values?

My issue involves implementing a fixed navigation bar with the following structure: <nav class='navigation'> <div :class="{ active: }" @click='scrollTo(".test1")'></div> <div :class=" ...

The pinFileToIPFS method in Pinata IPFS is currently unable to accept files uploaded by users

Currently, I am immersed in a project where I am utilizing React.js, Express.js, and Node.js to transform a user-provided image into an NFT on the Ethereum blockchain. To achieve this, I must first upload the image to IPFS (Pinata being my choice of servic ...

Issues with Bootstrap Contact Form submission

I found a helpful tutorial for creating a form at the following link: After following the tutorial, I added these scripts to the bottom of my contact form HTML: <script src='https://code.jquery.com/jquery-1.12.0.min.js'></script> ...

Experiencing a problem with the localhost connection

I've been trying to work on this issue using React and local host, but it keeps showing the direct file instead of the website. I've been stuck on this problem for the past 3-4 hours and still haven't been able to find a solution. I'm h ...

Looking for assistance in setting up a personalized slideshow to automatically play on its

Recently, I have taken responsibility for a project that was initiated by someone else. The website contains a customized slideshow on its homepage. To meet the client's requirements, I have already made some alterations to the appearance and feel of ...

The mysterious nature of view binding in Ember.js

Here's a unique challenge I'm facing. I've developed a sidebar component called SortableStopView that extends CollectionView. This sidebar contains a scrollable and sortable list of 'stops' which users can click on to navigate to t ...

Security Vulnerability in Ajax Callback Breakpoints

Imagine I have the following code snippet (partially pseudocode) $.ajax({ url: "/api/user", success: function(resp) { var data = JSON(resp) if (data.user.is_admin) // do admin thing else // do somet ...

"Enhancing user experience through file uploads using the onchange event

I'm currently working on implementing file upload functionality using the onchange event. I encountered an error stating that 'file is not defined.' //html file <input type="file" style="display: none;" onchange="angular.element(th ...

The text color remains the same even after the method has returned a value

I have a vuex query that returns a list of books. I want to display each book with a specific color based on its status. I tried using a method to determine the color name for each book and bind it to the v-icon, but it's not working as expected - no ...

Trouble resolving a timer interruption in JavaScript

Creating dynamic elements using PHP has brought me to a new challenge. I want to implement a functionality where the user can hover over an icon and see the related element, which should disappear after some time if the mouse leaves the icon. Additionally, ...

Combine collapse and popover in Bootstrap 3 for enhanced functionality

I'm facing some issues trying to use the badge separately from the collapse feature. $(function (e) { $('[data-toggle="popover"]').popover({html: true}) }) $('.badge').click($(function (e) { e.stopPropagation(); }) ) Check o ...

Defining the active element in the menu using JavaScript

I need help with my navigation menu: <ul> <li id="active"><a href="/">Home</a></li> <li><a href="/about/">About Us</a></li> <li><a href="/services/">Our Services</a>< ...

Ways to ensure that a URL is distinct once a link has been clicked

On my website list.php, I have a code snippet that changes the video in an iframe when a link is clicked. However, the URL remains as list.php instead of changing to something like list.php/Anohana10. How can I update the URL to reflect the selected video? ...

Is there a way to execute a code snippet just once when focusing on a specific field?

<form id="myForm"> <label for="fname">First name:</label><br> <input type="text" id="fname" name="fname"><br> <label for="mname">Middle name:</label> ...

If the ID (i.e. document.getElementById) is not found, then keep JavaScript running

I'm currently working on a JavaScript project where I need the script to gracefully handle missing div-ids and continue executing. I've looked into various solutions, but many involve either replacing the missing ID or placing information into an ...