Created
April 13, 2023 07:58
-
-
Save pabsan-0/3171673743b096e2f7d1474f463b29e9 to your computer and use it in GitHub Desktop.
Ros node template for nodejs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
const rosnodejs = require('rosnodejs'); | |
const { readFileSync, readdirSync } = require('fs'); | |
const { readFile } = require('fs').promises; | |
const express = require('express'); | |
const app = express(); | |
const path = require('node:path'); | |
let host = null | |
let port = null | |
let vel_topic = null | |
let apppath = null | |
function start_server() { | |
app.get("/host", (req, res) => { res.send(host) }) | |
app.get("/vel_topic", (req, res) => { res.send(vel_topic) }) | |
app.use(express.static(apppath)); | |
app.get('/', async (request, response) => { | |
response.send( await readFile("index.html", 'utf8')); | |
}); | |
app.listen(process.env.PORT || 5000, () => { | |
console.log(`NODE: App available on http://localhost:${5000}`) | |
}); | |
} | |
rosnodejs.initNode('http_serve', {node: {anonymous: true}}) | |
.then((nh) => { | |
nh.getParam("~host").then((val) => {console.log(val); host = val }).catch(console.log) | |
nh.getParam("~port").then((val) => {console.log(val); port = val }).catch(console.log) | |
nh.getParam("~vel_topic").then((val) => {console.log(val); vel_topic = val }).catch(console.log) | |
nh.getParam("~apppath").then((val) => {console.log(val); apppath = val; start_server() }).catch(console.log) | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment