Tushar Tushar - 1 month ago 9
Node.js Question

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];
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

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

Answer Source

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'