# Using p5.js functions with Node.js

**URL:** <https://discourse.processing.org/t/using-p5-js-functions-with-node-js/5431>\
**Category:** Libraries\
**Created:** [November 11, 2018, 9:27am UTC](https://discourse.processing.org/t/using-p5-js-functions-with-node-js/5431 "2018-11-11T09:27:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sarah](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/sarah/32/1675_2.png) [@Sarah](https://discourse.processing.org/u/Sarah)\
**Post date:** [November 11, 2018, 9:27am UTC](https://discourse.processing.org/t/using-p5-js-functions-with-node-js/5431/1 "2018-11-11T09:27:15Z")

</div>

Hi,

I’ve been experimenting with Node.js and [socket.io](http://socket.io), and I am now trying to use them together by making a simple shooter game.

Currently, I have a server file, which handles all the game logic and updates the game (collision detection, updating positions), then sends the updated state to the client, which renders it using p5.js on the client’s screen.

However, because my server.js file is a stand-alone javascript file (no index.html), it seems I have no way of accessing p5.js functions within in, which has some functions I would like to use (such as using vectors).

There are multiple resources that I have visited, such as the processing wiki and The Coding Trains videos, but they all don’t use p5.js functions or update it in the client (which I don’t want to do).

Is there any way I can use p5 functions in my server.js, to make it easier to update the game, or do I have to just stick with javascript functions?

I’m not sure if this is the place to ask this, but any questions or advice are welcome,  
Thanks!

---

<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:** [November 13, 2018, 11:44pm UTC](https://discourse.processing.org/t/using-p5-js-functions-with-node-js/5431/2 "2018-11-13T23:44:23Z")

</div>

> [@Sarah](#):
>
> , which has some functions I would like to use (such as using vectors).

I’ve got a PVector class in JS if you want: 😀  
[ProcessingJS.org/reference/PVector/](http://ProcessingJS.org/reference/PVector/)

> <https://gist.github.com/GoToLoop/acbf106aa784820aff23>

---

<div class="post-metadata">

**Author:** ![Sarah](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/sarah/32/1675_2.png) [@Sarah](https://discourse.processing.org/u/Sarah)\
**Post date:** [November 14, 2018, 8:11am UTC](https://discourse.processing.org/t/using-p5-js-functions-with-node-js/5431/3 "2018-11-14T08:11:51Z")

</div>

Thanks, that’s exactly what I needed 🙂!
