https://github.com/taniarascia/snek
🐍 A terminal-based Snake implementation written in JavaScript.
https://github.com/taniarascia/snek
game javascript node snake
Last synced: 10 months ago
JSON representation
🐍 A terminal-based Snake implementation written in JavaScript.
- Host: GitHub
- URL: https://github.com/taniarascia/snek
- Owner: taniarascia
- License: mit
- Created: 2019-04-03T23:14:34.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2021-10-22T21:56:14.000Z (over 4 years ago)
- Last Synced: 2025-04-02T03:45:34.876Z (over 1 year ago)
- Topics: game, javascript, node, snake
- Language: JavaScript
- Homepage: https://www.taniarascia.com/snake-game-in-javascript/
- Size: 90.8 KB
- Stars: 273
- Watchers: 4
- Forks: 44
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 🐍 Snek.js
[](https://opensource.org/licenses/MIT) [](https://www.npmjs.com/package/snekjs)
[](https://repl.it/github/taniarascia/snek)
A terminal-based Snake implementation written in JavaScript (Node.js).
### [Read the tutorial](https://www.taniarascia.com/snake-game-in-javascript/)

## Instructions
Use the arrow keys (`↑`, `↓`, `←`, `→`) or `W` `A` `S` `D` to navigate the snake up, down, left, or right. Eat the red dot to gain points. If the snake collides with the wall or its own tail, it's game over. Press `ENTER` to restart, and `Q`, `ESCAPE` or `CTRL` + `C` to quit the game.
## Installation
### Run without installing
The easiest way to play the game is to just run it in the terminal without installing anything!
```bash
npx taniarascia/snek
```
### Clone from repository
```bash
git clone https://github.com/taniarascia/snek
cd snek
# install and run via npm or yarn
npm i && npm run play
```
### npm module
Add the `snekjs` module.
```bash
npm i snekjs
```
Create the game.
```js
// index.js
const { UserInterface, Game } = require('snekjs')
const game = new Game(new UserInterface())
// Begin game
game.start()
```
Run the game.
```bash
node index.js
```
## Acknowledgements
- [Vanya Sergeev](https://sergeev.io) for pointing out my snake collision bug, for advising me to make a single, reusable draw method, for showing me how to properly bind methods between classes, and for overall guidance and inspiration.
- [Devin McIntyre](https://www.dev-eloper.com/) for general advice.
- Panayiotis Nicolaou's [JavaScript Snake for Web](https://medium.freecodecamp.org/think-like-a-programmer-how-to-build-snake-using-only-javascript-html-and-css-7b1479c3339e) for initial logic.
## Author
- [Tania Rascia](https://www.taniarascia.com)
## License
This project is open source and available under the [MIT License](LICENSE).