JavaScript Serve a file for a URL serve files from s3,serve files over http,serve file

I am trying to serve a file manually for a specific URL.

When I user the res.sendFile function I get the following error in my logs.

Object [object Object] has no method 'sendFile'

Express version : 4.13.3

It seems that this function is not available to use. There is a section about serving static content in the documentation but how would you serve it?

Updated code:

express = require('express');
app = express();

app.set('views', 'cloud/views');  // Specify the folder to find templates
app.set('view engine', 'ejs');    // Set the template engine
app.use(express.bodyParser());    // Middleware for reading request body
app.get('/hi', function(req, res){
  res.sendFile('index.html', function (err) {
    if (err) {
      console.log(err);
    }
    else {
      console.log('File sent!');
    }
  });
});

app.listen();

Error logs

I2015-09-22T07:08:37.766Z]v39 Ran custom endpoint with:
  Input: {"method":"GET","url":"/hi","headers":{"accept":"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8","accept-encoding":"gzip, deflate, sdch","accept-language":"en-US,en;q=0.8,fr;q=0.6,sq;q=0.4","cache-control":"no-cache","host":"......parseapp.com","pragma":"no-cache","upgrade-insecure-requests":"1","user-agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.93 Safari/537.36","version":..........."}}
  Result: Success
I2015-09-22T07:08:37.855Z]TypeError: Object [object Object] has no method 'sendFile'
    at app.js:13:7
    at callbacks (express_router.js:161:37)
    at param (express_router.js:135:11)
    at pass (express_router.js:142:5)
    at Router._dispatch (express_router.js:170:5)
    at Object.router (express_router.js:33:10)
    at next (connect_proto.js:240:15)
    at urlencoded (connect_urlencoded.js:51:37)
    at connect_bodyParser.js:64:7
    at json (connect_json.js:53:37)
Answer:1

I have a website that has an input form that submits to a php page and adds a players username to a database and counts the views of that player's name to a top 10 list. My friend tried out ...

I have a website that has an input form that submits to a php page and adds a players username to a database and counts the views of that player's name to a top 10 list. My friend tried out ...

I have created a custom jquery accordion and I am stuck with the code, when I click on accordion title, its opening both of the accordion where it should open the one where I have clicked, following ...

I have created a custom jquery accordion and I am stuck with the code, when I click on accordion title, its opening both of the accordion where it should open the one where I have clicked, following ...

  1. jquery accordion onclick event
  2. jquery accordion onclick
  3. jquery accordion onclick collapse
  4. jquery accordion close onclick
  5. jquery accordion collapse all onclick
  6. jquery accordion change image onclick
  7. jquery ui accordion close onclick

I am modelling the auth layer for a simple react/redux app. On the server side I have an API based on the devise_token_auth gem. I am using fetch to post a sign in request: const JSON_HEADERS = new ...

I am modelling the auth layer for a simple react/redux app. On the server side I have an API based on the devise_token_auth gem. I am using fetch to post a sign in request: const JSON_HEADERS = new ...

I'm trying to implement a messaging application in my game, so instead of clicking on the input text field manually, I want users to only press "enter", write something, then press "enter" again to ...

I'm trying to implement a messaging application in my game, so instead of clicking on the input text field manually, I want users to only press "enter", write something, then press "enter" again to ...