# Inherit/Use p5.Vector methods in NodeJS

**URL:** <https://discourse.processing.org/t/inherit-use-p5-vector-methods-in-nodejs/19909>\
**Category:** Coding Questions\
**Created:** [April 18, 2020, 9:26pm UTC](https://discourse.processing.org/t/inherit-use-p5-vector-methods-in-nodejs/19909 "2020-04-18T21:26:34Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![cake](https://avatars.discourse-cdn.com/v4/letter/c/b77776/32.png) [@cake](https://discourse.processing.org/u/cake)\
**Post date:** [April 18, 2020, 9:26pm UTC](https://discourse.processing.org/t/inherit-use-p5-vector-methods-in-nodejs/19909/1 "2020-04-18T21:26:34Z")

</div>

Hello! I’d like to inherit & use p5.Vector & its methods in a class I’m writing. / Use p5.Vector without a window.

This is backend code, I’ve seen that p5 cannot ‘run’ without a ‘window’ object. As it gives me ‘window’ is not defined.

The answer that I’m leaning towards is just having to write my own vector class. Not too bad of a solution, just wondered if anyone else wondered this?

With the p5.Vector class as an example I’ll probably just make my own 🙂

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [April 18, 2020, 10:07pm UTC](https://discourse.processing.org/t/inherit-use-p5-vector-methods-in-nodejs/19909/2 "2020-04-18T22:07:35Z")

</div>

If you copy p5.Vector.js

> <https://github.com/processing/p5.js/blob/master/src/math/p5.Vector.js>

and remove the line

```auto
import p5 from '../core/main';

```

…what breaks?

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [April 18, 2020, 10:14pm UTC](https://discourse.processing.org/t/inherit-use-p5-vector-methods-in-nodejs/19909/3 "2020-04-18T22:14:28Z")

</div>

Another option – use headless chrome, the way (I believe?) the project does for CI testing through mocha on Node.js 12.x.

> <https://github.com/processing/p5.js/issues/2174>
>
> For information, see https://github.com/ariya/phantomjs/issues/15105
> 
> This is …just an issue to note that testing should probably be moved over to headless chrome (Probably puppeteer: https://github.com/GoogleChrome/puppeteer ) when the ecosystem is a bit better (I can't see a way to integrate it in the grunt file easily yet)

Possibly see also:

[![](https://img.youtube.com/vi/bjULmG8fqc8/hqdefault.jpg "12.1: Introduction to Node - WebSockets and p5.js Tutorial") ](https://www.youtube.com/watch?v=bjULmG8fqc8)

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [April 18, 2020, 10:19pm UTC](https://discourse.processing.org/t/inherit-use-p5-vector-methods-in-nodejs/19909/4 "2020-04-18T22:19:13Z")

</div>

> [@cake](#):
>
> With the p5.Vector class as an example I’ll probably just make my own 🙂

> [@Using p5.js functions with Node.js](https://discourse.processing.org/t/using-p5-js-functions-with-node-js/5431/2):
>
> I’ve got a PVector class in JS if you want: grinning[ProcessingJS.org/reference/PVector/](http://ProcessingJS.org/reference/PVector/)

---

<div class="post-metadata">

**Author:** ![cake](https://avatars.discourse-cdn.com/v4/letter/c/b77776/32.png) [@cake](https://discourse.processing.org/u/cake)\
**Post date:** [April 18, 2020, 10:34pm UTC](https://discourse.processing.org/t/inherit-use-p5-vector-methods-in-nodejs/19909/5 "2020-04-18T22:34:38Z")

</div>

Both of these are great resources thank you! 🙂
