Giter Club home page Giter Club logo

Comments (5)

typicode avatar typicode commented on September 12, 2024

Hi,

Tried it on Windows 8.1 with json-server 0.5.4 with this:

{
    "posts": [
        {"id": 1, "title": "foo"}
    ]
}

And I'm not able to reproduce.

Could you please run the following script and tell me if you have any errors?

var fs = require('fs')
JSON.parse(fs.readFileSync('mockAPI.json'))

from json-server.

perqa avatar perqa commented on September 12, 2024

I think you nailed it, but I still don't understand what's happening. I am successfully running grunt and a load of tasks associated with it. I got the same error when executing your code snippet as I got before. I put your code in a file called test.js and executed from CMD.

C:\path\to\webroot>node test.js

undefined:1
´╗┐{
^
SyntaxError: Unexpected token ´╗┐
    at Object.parse (native)
    at Object.<anonymous> (C:\path\to\webroot\test.j
s:2:6)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:906:3

This seems to be a problem with my Node installation rather than json-server... but if you have any ideas I would be ever so grateful to hear them.

from json-server.

typicode avatar typicode commented on September 12, 2024

Hmm, personally I'd check the .json file. Maybe it's a file encoding issue.

To check that, you could create a JSON file using this code:

// create.js
var fs = require('fs')
fs.writeFileSync('test.json', JSON.stringify({
  issues: [
    { id: 1, title: 'foo' }
  ]
}))

And try to consume it with the other code to see if there's still an error.

from json-server.

perqa avatar perqa commented on September 12, 2024

You were absolutely right! There was something invisibly wrong with that file. The encoding looked alright (UTF-8). No matter if I deleted everything in it and typed it back manually, it still crashed. I had to delete the file and create a new, seemingly identical, one, but then it finally worked. I am very grateful for your help, and sorry for wasting your time with such nonsense. I'm really looking forward to using the software now! :-)

from json-server.

typicode avatar typicode commented on September 12, 2024

No worries :)
Really happy that I could help.

from json-server.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.