Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用node.js调用同一目录中的文件时出错_Javascript_Node.js - Fatal编程技术网

Javascript 使用node.js调用同一目录中的文件时出错

Javascript 使用node.js调用同一目录中的文件时出错,javascript,node.js,Javascript,Node.js,更新:我能够在我的代码中找到错误。问题是我没有在console.log中为我的notes.js关闭左括号 我开始在node.js上学习如何调用从本地系统上的文件创建的其他函数。我有目录节点notes,其中有两个javascript文件,app.js和notes.js。我正在我的app.js中调用我的notes.js。我做了一个简单的console.log()调用,以确保它在我的notes.js中正常工作。但是当我尝试使用命令node app.js运行代码时,我得到了下面的错误 更新:我正在使用节

更新:我能够在我的代码中找到错误。问题是我没有在
console.log
中为我的
notes.js
关闭左括号

我开始在
node.js
上学习如何调用从本地系统上的文件创建的其他函数。我有目录
节点notes
,其中有两个
javascript
文件,
app.js
notes.js
。我正在我的
app.js
中调用我的
notes.js
。我做了一个简单的
console.log()
调用,以确保它在我的
notes.js
中正常工作。但是当我尝试使用命令
node app.js
运行代码时,我得到了下面的错误

更新:我正在使用节点10.0.0

我不知道这意味着什么,所以请有人解释一下错误是什么,以及我如何修复它。下面我将发布我的
app.js
notes.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")
}

});
console.log("Calling 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")
}

});
console.log("Calling notes.js")
notes.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")
}

});
console.log("Calling notes.js")
在notes.js中,您缺少一个用于结束字符串的

console.log(“调用notes.js”)
应该是
console.log(“调用notes.js”)

因此,在notes.js中,您会得到一个
语法错误:无效或意外的标记

,您缺少一个
来结束字符串

console.log(“调用notes.js”)
应该是
console.log(“调用notes.js”)


因此,您会得到一个
语法错误:无效或意外标记

看起来您的代码中有一个未在此处复制的键入错误。您的意思是,我遗漏了一些代码,因为我复制了所有代码。您的代码中有一个未在此处复制的键入错误。您的意思是,我遗漏了一些代码,因为我复制了所有这些。