Phaser NPM: How do I access it?

HI All, I’ve worked with Phaser on and off for a few years now. I’m trying to get into NodeJS and I thought building a game with Phaser using it would be a cool refresher. Right now I’ve got a very simple project that using express loads an index.html page.

I want to move away from javascript linking in my HTML to using Node Modules. I know that phaser do have a module, but the link is currently dead. I’ve downloaded phaser using the following:

npm install phaser

I’ve setup my server script to include the phaser module.

var sitePath = process.argv[2] || ".";
var port = 4242;
 
// Libraries
var express = require('express');
var phaser = require('phaser');
var app = express();
 
// Request logging
app.use(function(req, res, next) {
    console.log(req.url);
    next();
});
 
// Start server
console.log(sitePath);
console.log("Starting server in: " + __dirname + '/' + sitePath);
app.use(express.static(__dirname + '/' + sitePath));
app.listen(port, function() { 
    console.log("Server running at: http://localhost:" + port)
});

My question is, how do I access phaser from other JS? That might not even be how it works. Everything I’ve seen indicates that you access it via the this script alone. Does it being here make it global in scope? Also if there are any tutorials or examples I could follow, that would be great.

You just require it again

e.g:
// file1.js
var phaser = require(‘phaser’);

// file2.js
var phaser = require(‘phaser’);

This applies to all the dependencies you have installed

1 Like