Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

restify.serveStatic is not a function error

I am using following script but this script is throwing error that serveStatic is not a function I have installed restify using this command "npm install --save restify"

var restify = require('restify');
var builder = require('botbuilder');

var server = restify.createServer();

server.listen(process.env.port || process.env.PORT || 3978, function () { });



// Create the chat connector for communicating with the Bot Framework Service
var connector = new builder.ChatConnector({
    appId: '***',
    appPassword: '***'
});

// Listen for messages from users 
server.post('/api/messages', connector.listen());

server.get('/', restify.serveStatic({
 directory: __dirname,
 default: '/index.html'
}));


var bot = new builder.UniversalBot(connector, function (session) {
    var msg = session.message;
    if (msg.attachments && msg.attachments.length > 0) {
     // Echo back attachment
     var attachment = msg.attachments[0];
        session.send({
            text: "You sent:",
            attachments: [
                {
                    contentType: attachment.contentType,
                    contentUrl: attachment.contentUrl,
                    name: attachment.name
                }
            ]
        });
    } else {
        // Echo back users text
        session.send("You said: %s", session.message.text);
    }
});

The above code is throwing this error while executing

C:\Users\Tushar\botforarticle\app.js:20
server.get('/', restify.serveStatic({
                        ^

TypeError: restify.serveStatic is not a function
    at Object.<anonymous> (C:\Users\Tushar\botforarticle\app.js:20:25)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.runMain (module.js:604:10)
    at run (bootstrap_node.js:394:7)
    at startup (bootstrap_node.js:149:9)
    at bootstrap_node.js:509:3
like image 590
Tushar Avatar asked Jul 02 '17 09:07

Tushar


1 Answers

Apparently, this has changed in v5.0.0 (released only a few days ago), but the documentation hasn't been updated yet.

Try this:

server.get('/', restify.plugins.serveStatic({
 directory: __dirname,
 default: '/index.html'
}));
like image 125
robertklep Avatar answered Sep 21 '22 15:09

robertklep