【发布时间】:2018-09-09 07:56:28
【问题描述】:
我使用的是 macOS 10.13.4 和 Node 版本 8.11.4。 我正在尝试遵循来自 tutsplus.com 的名为 Node From Scratch 的简单教程。第二个视频首先需要 FS 模块,然后在文件上调用 watch 方法来监视文件的更改。
'use strict';
const fs = require( 'fs' );
fs.watch( 'stylesheet.css', () => console.log( 'File Has Been Updated' ) );
console.log( "Application Has Started And Is Listening For Changes" );
每当我尝试使用 Node 在终端中运行 js 文件时,我都会收到错误消息
fs.js:1384
throw error;
^
Error: watch stylesheet.css ENOENT
at _errnoException (util.js:992:11)
at FSWatcher.start (fs.js:1382:19)
at Object.fs.watch (fs.js:1408:11)
at Object.<anonymous> (/Downloads/filewatcher.js:5:4)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Function.Module.runMain (module.js:693:10)
我似乎无法在网上找到任何关于为什么会发生这种情况的信息。谁能帮忙。
【问题讨论】:
-
你有一个名为 stylesheet.css 的文件吗?
-
@ashishsingh 是的,我愿意
-
我不确定,请检查一次拼写,它应该与这个js文件在同一目录下
-
@ashishsingh 谢谢,是的,我已经检查了拼写,它在同一个目录中,但我仍然没有运气。
-
哦,如果您不是初学者并且可以读取文件,您可以做一个实验来读取类似位置的文件;将它命名为 b.css 并尝试阅读它.. 这样你就知道你的设置是正确的
标签: javascript node.js node-modules fs