DarkN3ss DarkN3ss - 11 months ago 300
Node.js Question

res.sendFile is not a function Node.js

I am not able to send a HTML file using node.js

So first off this is the error I am getting

Application has thrown an uncaught exception and is terminated:
TypeError: res.sendFile is not a function
at Server.<anonymous> (C:\Program Files\iisnode\www\test\app.js:4:6)
at emitTwo (events.js:88:13)
at Server.emit (events.js:173:7)
at HTTPParser.parserOnIncoming [as onIncoming] (_http_server.js:529:12)
at HTTPParser.parserOnHeadersComplete (_http_common.js:89:23)

and my app.js code is

var http = require('http');

http.createServer(function (req, res) {
res.sendFile('test.html', { root: __dirname });

If I am missing something simple, I am sorry as this is the first node.js program I have made

Answer Source

sendFile only in Express module.

Try this code

 var express = require('express');
 var app = express();
 app.get('/', function(req, res) {