I am following this guide: https://github.com/opentok/opentok-node/tree/master/sample/HelloWorld
The project compiles fine, but when I start, I get this error:
Error:
> Error: Cannot find module 'ejs'
> at Function.Module._resolveFilename (module.js:470:15)
> at Function.Module._load (module.js:418:25)
> at Module.require (module.js:498:17)
> at require (internal/module.js:20:19)
> at new View (C:\pruebaTokbox\node_modules\express\lib\view.js:80:30)
> at Function.render (C:\pruebaTokbox\node_modules\express\lib\application.js:570:12)
> at ServerResponse.render (C:\pruebaTokbox\node_modules\express\lib\response.js:971:7)
> at C:\pruebaTokbox\index.js:33:7
> at Layer.handle [as handle_request] (C:\pruebaTokbox\node_modules\express\lib\router\layer.js:95:5)
> at next (C:\pruebaTokbox\node_modules\express\lib\router\route.js:137:13)
My code: package.json
{
"name": "opentok-helloworld-sample",
"version": "0.0.0",
"description": "Group video chat app to demonstrate the basic functionality of OpenTok",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"ejs": "^0.8.6",
"express": "^3.5.0",
"opentok": "^2.5.0"
}
}
index.js
// Dependencies
var express = require('express'),
OpenTok = require('opentok');
// Verify that the API Key and API Secret are defined
var apiKey = 111111,
apiSecret = '1111111';
if (!apiKey || !apiSecret) {
console.log('You must specify API_KEY and API_SECRET environment variables');
process.exit(1);
}
// Initialize the express app
var app = express();
app.use(express.static(__dirname + '/public'));
// Initialize OpenTok
var opentok = new OpenTok(apiKey, apiSecret);
// Create a session and store it in the express app
opentok.createSession(function(err, session) {
if (err) throw err;
app.set('sessionId', session.sessionId);
// We will wait on starting the app until this is done
init();
});
app.get('/', function(req, res) {
var sessionId = app.get('sessionId'),
// generate a fresh token for this client
token = opentok.generateToken(sessionId);
res.render('index.ejs', {
apiKey: apiKey,
sessionId: sessionId,
token: token
});
});
// Start the express app
function init() {
app.listen(3000, function() {
console.log('You\'re app is now ready at http://localhost:3000/');
});
}
and index.ejs
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>OpenTok Hello World</title>
<script src="//static.opentok.com/webrtc/v2.2/js/TB.min.js"></script>
<script type="text/javascript">
var apiKey = '<%= apiKey %>';
var sessionId = '<%= sessionId %>';
var token = '<%= token %>';
</script>
<script src="/public/js/helloworld.js"></script>
</head>
<body>
<h2>Hello, World!</h2>
<div id="publisher"></div>
<div id="subscribers"></div>
</body>
</html>
The original file, didnt have the public path, just JS, but that path was wrong.
The solution was to execute these 2 commands