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”)
因此,您会得到一个语法错误:无效或意外标记
看起来您的代码中有一个未在此处复制的键入错误。您的意思是,我遗漏了一些代码,因为我复制了所有代码。您的代码中有一个未在此处复制的键入错误。您的意思是,我遗漏了一些代码,因为我复制了所有这些。