Mohamed Ali
Mohamed Ali

Reputation: 782

Error when calling file in same directory using node.js

Update: I was able to find the error in my code. The problem was that I didn't close my opening parenthesis with closing ones in my console.log for my notes.js.

I started a course on node.js and I am learning how to call other functions created from files on my local system. I have the directory node-notes in which I have two javascript files, app.js and notes.js. I am calling my notes.js in my app.js. I made a simple console.log() call just to make sure its working right in my notes.js. But when I try to run my code using the command node app.js I am getting the error below.enter image description here

Update: I am using Node 10.0.0

I have no idea what this means so can someone please explain what the error is and how I can fix it. Below I will post both codes for my app.js and notes.js

app.js

console.log("STARTING app.js")



// calling modules using require
// calling functions in fs module and putting in the 
// variable fs

const fs = require('fs');
const os = require('os');
const notes = require('./notes.js');


var user = os.userInfo();
console.log(user);


fs.appendFile('greetings.txt', 'Hello World!' + user.username , function(err){

if(err){
    console.log("There was an error")
}else{
    console.log("It was successful")
}

});

notes.js

console.log("Calling notes.js")

Upvotes: 0

Views: 121

Answers (1)

Kristianmitk
Kristianmitk

Reputation: 4778

In notes.js you are missing a " to end the string.

console.log("Calling notes.js) should be console.log("Calling notes.js")

Thus you get a SyntaxError: Invalid or unexpected token

Upvotes: 3

Related Questions