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 }));
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);
control x
to save and quit
from the root
node index.js
now from postman
`http://your-server-ip:3000/api`
You will see
API is online
Top comments (0)