Node.js - Error: Undefined:0 SyntaxEncountered an unexpected end of input syntax error

Exploring Node.js and Backbone.js for the first time. Using the book "Backbone Blueprints" but encountering issues with the provided code to set up the webserver.

Node.js is installed and running fine. Here's the package.json code:

{
  "name": "simple-blog",
  "description": "A basic blog.",
  "version": "0.1.0",
  "scripts": {
    "start": "nodemon server.js"
  },
  "dependencies": {
    "express": "3.x.x",
    "ejs": "~0.8.4",
    "bourne": "0.3"
  },
  "devDependencies": {
    "nodemon": "latest"
  }
}

This is the problematic server.js code:

var express = require('express');
var path = require('path');
var Bourne = require("bourne");

var app = express();
var posts = new Bourne("simpleBlogPosts.json");
var comments = new Bourne("simpleBlogComments.json");

app.configure(function(){
    app.use(express.json());
    app.use(express.static(path.join(__dirname, 'public')));
});

app.get('/*', function (req, res) {
    res.render("index.ejs");
});

app.listen(3000);

Error message when trying to start the server:

> nodemon server.js

11 Mar 19:35:22 - [nodemon] v1.3.7
11 Mar 19:35:22 - [nodemon] to restart at any time, enter `rs`
11 Mar 19:35:22 - [nodemon] watching: *.*
11 Mar 19:35:22 - [nodemon] starting `node server.js`
undefined:0

^
SyntaxError: Unexpected end of input
    at Object.parse (native)
    at new Bourne (C:\Users\MyName\WebstormProjects\simpleBlog\node_modules\bou
rne\lib\bourne.js:52:30)
    at Object.<anonymous> (C:\Users\MyName\WebstormProjects\simpleBlog\server.j
s:6:13)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:501:10)
    at startup (node.js:129:16)
    at node.js:814:3

Checked for common mistakes like undefined variables or missing brackets, but couldn't find any issues. Webstorm flags an error in the app.configure function as well.

The book is recent (2014), and I'm self-learning Backbone.js with Node.js and Express thanks to it.

This isn't a homework question, just seeking help to progress with my learning journey! Appreciate any assistance!

Answer №1

The issue at hand is that bourne is anticipating for simpleBlogPosts.json to possess a valid JSON document, however the file does not meet those criteria.

A possible solution would be to remove simpleBlogPosts.json and then restart the server in order to generate a valid JSON file, specifically one with contents of []. It is probable that the same action will need to be taken with simpleBlogComments.json.

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

Storing Radio Buttons and Checkboxes Using LocalStorage: A Simple Guide

Is there a way to save and retrieve values from localStorage for input types "radio" and "checkbox"? I've tried using the same code that works for text and select elements, but it doesn't seem to be saving the values for radio and checkbox. Can s ...

Vue.js and the hidden input value that remains unseen

I am currently developing a shopping list application using Vue.js and I was wondering if there is a conventional method to achieve my requirements. My app consists of a list of items with add and delete buttons: https://i.stack.imgur.com/yQfcz.png const ...

Storing ng-change event for a checkbox in AngularJS in a valid manner

I have a requirement where I need to handle multiple input checkboxes. The goal is to store the changed checkbox events in an array and then save them when the user submits the changes. <td><input type="checkbox" class="switch" ng-model="each_val ...

Error encountered while parsing JSON data with Gson: MalformedJsonException

Hello, I am working on a project that involves parsing JSON data. However, I keep encountering a Malformed exception while trying to do so. Below is the code I'm currently using: Object listOfGroups = sthService.getSthList(); Gson gson = new ...

When testing, Redux form onSubmit returns an empty object for values

Is it possible to pass values to the onSubmit handler in order to test the append function? Currently, it always seems to be an empty object. Test Example: const store = createStore(combineReducers({ form: formReducer })); const setup = (newProps) => ...

Issue with Redux-form's type prop not functioning as expected with checkbox and radio components

Hey there, I'm new to working with redux forms and I've been trying to figure out how to use input types other than "text". I've read through the documentation but for some reason, types like "checkbox" or "radio" are not showing up in the b ...

Error: JavaScript object array failing to import properly

In my code, I have an array of objects named trace which is defined as follows: export const trace: IStackTrace[] = [ { ordered_globals: ["c"], stdout: "", func_name: "<module>", stack_to_render: [], globals: { c: ["REF" ...

Encountering an undisclosed CORS error on all requests from Angular frontend to NodeJS Express Server during preflight 200

After thorough testing with Postman, my backend server is functioning properly and generating the desired responses for all requests. However, my Angular app is encountering an unknown CORS error on every request despite receiving a 200 Preflight response ...

Generating and traversing a JSON object with three dimensions

After exploring various topics on this site, I haven't been able to find a clear solution for my specific problem. I am facing a scenario where I need to populate three select boxes with options from a multidimensional array that follows the structur ...

What is the process for creating a JSON message to be sent using Amazon SES?

Whenever I attempt to send an email using Amazon-SES, I keep encountering the following error: Error encountered while parsing parameter '--raw-message': JSON is invalid. A property name enclosed in double quotes is expected: line 1 column 2 (cha ...

Exploring the possibilities of web scraping using phantomJS and NodeJS

Currently, I'm working through a tutorial found at the following link: However, when I execute the code provided in the tutorial: var host = 'http://www.shoutcast.com/?action=sub&cat=Hindi#134'; var phantom = require('phantom& ...

Is it possible to modify the background color of a checkbox?

I am looking to modify the background color of the checkbox itself, specifically the white square. I have spent a lot of time researching this topic but most articles suggest creating a div and changing its background color, which does not affect the whi ...

Encountering difficulty when trying to initiate a new project using the Nest CLI

Currently, I am using a tutorial from here to assist me in creating a Nest project. To start off, I have successfully installed the Nest CLI by executing this command: npm i -g @nestjs/cli https://i.stack.imgur.com/3aVd1.png To confirm the installation, ...

What happens to the arrays within my function?

I am working on a controller code: public function getChartData(){ $result["categories"] = array(); $result["series"] = array(); $sales = $this->db->Execute("select id_tenant, nama_kantin, count(id_penjualan) as jumlah_penjualan, s ...

What is the method for implementing type notation with `React.useState`?

Currently working with React 16.8.3 and hooks, I am trying to implement React.useState type Mode = 'confirm' | 'deny' type Option = Number | null const [mode, setMode] = React.useState('confirm') const [option, setOption] ...

What is the process for converting a UTC datetime string into the local timezone of users?

I am utilizing Laravel 5.7 for the API and Vue for the frontend development. The API response includes a user's last seen timestamp in UTC format by default, like this: last_seen: "2019-04-17 05:20:37". Laravel API code: $user_details = array( ...

Remove all HTML tags except for those containing a specific class

Looking for a regex that removes all HTML tags except the "a" tags with the "classmark" class For example, given this HTML string: <b>this</b> <a href="#">not match</a> <a href="#" target="_blank" ...

Run a script tag prior to displaying the modal

Currently, I am attempting to display a bootstrap modal with dynamic content. One of the values being passed to the modal is the HTML that should appear inside it. The issue I am facing is that within the HTML content being passed, there is a script tag t ...

Navigating with Node.js and angular

I'm struggling with redirecting POST requests using Node.js, Express, and Angular. Typically, we'd use forms like this: index.ejs <!DOCTYPE html> <html> <head> <title>Redirect Example</title> </head> <bo ...

Retrieve the index of a v-for loop and then send it as a parameter to a specific function

When working with a select element generated by a v-for loop in Vue, it is important to be able to retrieve the index of the selected option. This way, you can use that index in a function for further processing. However, I have been struggling to achieve ...