Turn your Json-server into a live and functional URL

I have my json database (db.json) stored on Json-server at this URL: http://localhost:3000/places

Now I am looking to transfer this json database to a real hosting service.

The main question here is how can I access the 'places' array in db.json using the URL of the real hosting site?

An example approach that is not functioning (just for clarification purposes):

https://domaindomain.org/db.json[places] or https://domaindomain.org/db.json[0]

Answer №1

JSON server is a specialized tool that allows for searching and editing JSON files in response to HTTP requests.

It's not just a simple flat JSON file, as it requires specific handling.

You can't simply upload a JSON file to any HTTP server and expect the same API functionality.

The official documentation describes it as:

Crafted with love for front-end developers looking for a quick way to prototype and mock back-end behavior.

Prior to production, you'll need to swap out your JSON server prototype with custom server-side code offering similar features (potentially interfacing with an actual database). This new setup should then be deployed on your server.

Answer №2

If you're using a shared host, consider utilizing JavaScript for parsing JSON to find solutions tailored to your needs.

Accessing a specific part of a JSON file directly via URL isn't possible; you'll need a page that can parse URL parameters and return the relevant chunk of data from the JSON file based on the query.

There are various ways to achieve this, with options including JavaScript.

input

http://localhost:3000/index.html

output

{
'places':[
{},{}
]
}

index.html Code

fetch('http://localhost:3000/places')
.then(response => response.json())
.then(json => document.body.innerHTML=JSON.stringify(json['places']));

Answer №3

Make sure to retrieve or open the file before trying to access its properties.

fetch('http://example.com/movies.json')
  .then((response) => response.json())
  .then((data) => console.log(data["places"]));

Answer №4

If you're using a VPS, consider installing node on your system and launching your database server. You can access it via yourip:3000, then add domain.com to that IP in your DNS records. If node shuts down when you log out, look into using supervisor, which is a tool that ensures your command stays active indefinitely.

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

Guidelines for forming a JSON variable using a SOAP Response

Currently using ASP.NET 4.0, I am faced with the task of sending a SOAP (XML) Response to a JSON variable in javascript on the page. The aim is to access the variable and its properties just like any other JSON variable would be accessed. The challenge lie ...

Is there a way to create a customized calendar in Node.js?

I am looking for a way to showcase a calendar in a localized format, not only in terms of language but also supporting non-Gregorian calendars such as Persian, Chinese, or Buddhist. In the past, when I worked with Java, I relied on ICU4J for this task. Ho ...

The implementation of Axios cancel token failed to function properly in a real-time search feature within a React application

I'm currently developing a dynamic search feature using React, where users can input search terms and receive JSON results. I attempted to implement axios cancel token for this functionality, but it doesn't seem to be working properly and I' ...

The function to focus on this.$refs[("p" + index)] element is not available

I need help transforming a div into an input box when clicked, allowing me to edit the post inside a loop. Here is the button found on the post: <a @click="setFocusEdit(index)" v-if="isAuthor(post)" href="#" >Edit Me</a> And here is the spec ...

What is the best way to insert a PHP Variable into the URL string for file_get_contents?

How can I replace the number 1 in the URL provided below with a PHP variable obtained from the website URL? Everything is functioning properly except for my difficulty in getting a variable to work within the file_get_contents function in the middle of t ...

Ways to forward a webpage once validation has been completed

I have a login form that is being validated using jQuery/Ajax to receive a JSON response. The form calls a PHP page called add-data.php. Upon successful validation, I want to redirect to another page after displaying the message Successfully logged!: if ...

Heroku is incompatible with deploying MERN applications

I've been working on deploying my React app through NodeJS and Heroku, but I keep encountering an issue in the browser. Uncaught SyntaxError: Unexpected token '<' Resulting in a blank white page being displayed. I've tried sever ...

The PHP header() function is not properly redirecting the page, instead it is only displaying the HTML

After double checking that no client sided data was being sent beforehand and enabling error reporting, I am still encountering issues. The issue revolves around a basic login script with redirection upon validation. <?php include_once "database- ...

Determining the most appropriate time to utilize the 'async' built-in function in ES2017 versus implementing 'npm i async' can depend on a variety of factors such

I recently discovered that async/await is a feature of ES2017, however, in some of my previous projects I had to use the package async to implement async/await functionality. Is there a simple way to determine when async can be used without importing it? ...

Leveraging React Hooks for managing the Data Provider and Data Context functionality

Currently, I am revamping my DataProvider by upgrading it from a class component to a functional component utilizing React Hooks. I suspect that the issue lies in how I am setting up my context consumer, but I am struggling to find an effective way to tes ...

Transmitting data from Javascript/Ajax to a form

I am using jQuery to calculate a price: $('.label_1').click(function(){ var total = 0; $('.option_1:checked').each(function(){ total += parseInt($(this).val()); }); $('#total').html(' ...

I'm currently utilizing lint in my Angular 2+ project. Is there a way to arrange the constructor parameters in alphabetical order

I am struggling to organize the constructor parameters in TypeScript while using TSLINT with Angular9. I am looking for a rule similar to member-ordering that can help me sort them effectively. constructor( // Sort these private readonly router: R ...

Rendering on the server with React, React-Router, and Express

I'm currently in the process of setting up server-side rendering for my react application and I'm utilizing the fantastic react-router module to enable it to manage non-js scenarios (such as certain crawlers or users with javascript disabled). Ne ...

My string is being cut off due to the HTML value

My webpage utilizes HTML5 to enable file uploads directly from the browser. The uploaded file is a PDF that needs to be displayed within an <input type="text"/> The following is my code snippet: var files = evt.target.files; // FileList object // ...

In Go programming language, modifying the second item in a list will have a direct impact

If you're stuck on what to say, take a closer look at the code and its resulting output. Here's the code snippet: package main import ( "encoding/json" "fmt" ) type Human struct { N string `json:"n"` ...

Creating tables and defining their structure with jQuery for HTML can be done using the following steps

I have retrieved values from the database in a variable by parsing it from JSON format. Now, I need to generate an HTML table structure as shown below: <table class="table dataList fiberEngg"> <tbody> <tr> <td& ...

Exploring the power of Next JS by implementing server-side rendering with a

I am faced with the challenge of incorporating navigation into my layout by utilizing data from an API and then displaying it on specific pages. The catch is that the Layout file is not located in the pages folder, meaning I cannot use traditional getStati ...

Retrieving Hidden Gems with Elastic Search

In working with elastic search using Scala and REST, I have structured my data as shown in the JSON input file below: { "bookTitle" : "textbook", "bookAuthors" : [ { "authorId" : "01", "authorName" : "author1" ...

Problem with jQuery's UI autocomplete functionality

Implementing jQ UI Autocomplete with multiple values Below is how my function is structured: mailto_input.bind( "keydown", function( event ) { if ( event.keyCode === $.ui.keyCode.TAB && $( this ).data( "autocomplete" ).menu.active ) { ...

utilizing array.map() to nest multiple layers of arrays

I am facing a challenge with a JavaScript array structure that contains three top-level objects. Each of these objects has an "teamLineup" array, which in turn holds two more objects named "team". These "team" objects have another array called "starters", ...