Cover image for I built a simple rest API with node and a Raspberry Pi

I built a simple rest API with node and a Raspberry Pi

teamallnighter profile image Chris Connelly ・1 min read

This was a lot of fun for me and I will be updating this more as I go!

I installed ubuntu server on a raspberry pi 4.

From var/www/html

mkdir api && cd api
sudo npm init -y
sudo npm install express
touch index.js && sudo nano index.js

For now I am going to just make one GET response to test.

var express = require('express');        
var app = express();                 
var bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({ extended: true }));
var port = process.env.PORT || 8080;  
const router = express.Router();
router.get('/', function(req, res) {
    res.json({ message: 'API is Online!' });   

app.use('/api', router);
console.log('Listening on port ' + port);

control x to save and quit

from the root

node index.js

now from postman


You will see

API is online

Posted on by:

teamallnighter profile

Chris Connelly


My name is Chris. I love webdev so much I quit my well paying job of fifteen years to go back to school and start my own freelance compant


markdown guide