DEV Community

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

Posted on

1

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

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
Enter fullscreen mode Exit fullscreen mode
sudo npm init -y
Enter fullscreen mode Exit fullscreen mode
sudo npm install express
Enter fullscreen mode Exit fullscreen mode
touch index.js && sudo nano index.js
Enter fullscreen mode Exit fullscreen mode

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 }));
app.use(bodyParser.json());
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);
app.listen(port);
console.log('Listening on port ' + port);
Enter fullscreen mode Exit fullscreen mode

control x to save and quit

from the root

node index.js
Enter fullscreen mode Exit fullscreen mode

now from postman

`http://your-server-ip:3000/api` 
Enter fullscreen mode Exit fullscreen mode

You will see

API is online
Enter fullscreen mode Exit fullscreen mode

Image of Stellar post

Check out Episode 1: How a Hackathon Project Became a Web3 Startup πŸš€

Ever wondered what it takes to build a web3 startup from scratch? In the Stellar Dev Diaries series, we follow the journey of a team of developers building on the Stellar Network as they go from hackathon win to getting funded and launching on mainnet.

Read more

Top comments (0)

Sentry image

Make it make sense

Only the context you need to fix your broken code with Sentry.

Start debugging β†’

πŸ‘‹ Kindness is contagious

Engage with a wealth of insights in this thoughtful article, valued within the supportive DEV Community. Coders of every background are welcome to join in and add to our collective wisdom.

A sincere "thank you" often brightens someone’s day. Share your gratitude in the comments below!

On DEV, the act of sharing knowledge eases our journey and fortifies our community ties. Found value in this? A quick thank you to the author can make a significant impact.

Okay