Reputation: 191
I'm trying to write a simple file web file server. I'm using PhpStorm.
var http = require('http');
var fs = require('fs');
function send404Request(response) {
response.writeHead("404", {"Content-Type": "text/html"});
response.write("404 Page Not Found");
response.end();
}
function onRequest(request, response) {
if (request.method === 'GET' && request.url === '/') {
response.writeHead("200", {"Content-Type": "text/plain"});
fs.createReadStream("./index.html").pipe(response);
} else {
send404Request(response);
}
}
http.createServer(onRequest).listen(8888);
console.log("file server is now running...");
However, PhpStorm says "unresolved function or method pipe()"
Here is my setting for JavaScript libraries in PhpStorm:
Any idea where goes wrong?
Upvotes: 0
Views: 3132
Reputation: 661
In the end of 2019 faced the same issue but in my gulpfile.js.
Downloading the @types/gulp library in PHPStorm resolved both issues.
Upvotes: 1
Reputation: 1
Here is a workaround I am using. Instead of
fs.createReadStream("./index.html").pipe(response);
I am using:
response.write(fs.readFileSync("./index.html"));
This works well for intelliJ IDEA.
Upvotes: -1
Reputation: 26
In Settings/Project Settings/JavaScript/Libraries, Download "node-DefinitelyTyped". This work for me. I had the same issue as your.
Upvotes: 1
Reputation: 960
Perhaps you need to wait for the stream to open:
var readStream = fs.createReadStream("./index.html");
readStream.on('open', function () {
readStream.pipe(response);
});
Additionally, add this to catch any errors that might be going on:
readStream.on('error', function(err) {
console.log(err.message);
});
Upvotes: 0