https://github.com/alexsch01/noer
Simple node webserver
https://github.com/alexsch01/noer
node server simple web webserver
Last synced: about 2 months ago
JSON representation
Simple node webserver
- Host: GitHub
- URL: https://github.com/alexsch01/noer
- Owner: alexsch01
- License: mit
- Created: 2023-01-02T11:39:36.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2025-08-04T11:58:17.000Z (11 months ago)
- Last Synced: 2026-04-30T12:36:59.196Z (about 2 months ago)
- Topics: node, server, simple, web, webserver
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/noer
- Size: 146 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# noer
Simple node webserver
https://github.com/alexsch01/noer
### Calculator Example
---
**public/index.html**
```html
Calculator
Calculator
Add
Subtract
Multiply
Divide
```
**public/index.js**
```js
const forms = document.querySelectorAll('form[class="noerForm"]')
for (const form of forms) {
form.onsubmit = async (e) => {
e.preventDefault()
const data = Object.fromEntries(new FormData(e.target).entries())
document.querySelectorAll('[name="left"]').forEach(elem => {
elem.value = ''
})
document.querySelectorAll('[name="right"]').forEach(elem => {
elem.value = ''
})
let json
try {
const resp = await fetch('/getData', {
method: 'POST',
body: JSON.stringify(data),
})
json = await resp.json()
} catch(_) {}
if (json === undefined) {
document.querySelector('[id="results"]').innerHTML = 'Uh oh - check your server'
return
}
document.querySelector('[id="results"]').innerHTML = json.results
}
}
```
**server.js**
```js
//@ts-check
const noer = require('noer')
noer({
publicDir: 'public/',
port: 8080,
routes: {
'/getData': async (data) => {
let answer, operator
const left = parseFloat(data.left)
const right = parseFloat(data.right)
if(data.action === 'add') {
answer = left + right
operator = '+'
}
if(data.action === 'subtract') {
answer = left - right
operator = '-'
}
if(data.action === 'multiply') {
answer = left * right
operator = 'x'
}
if(data.action === 'divide') {
answer = left / right
operator = '/'
}
let results = ''
if(Number.isFinite(answer)) {
results = `${left} ${operator} ${right} = ${answer}`
}
return JSON.stringify({ results })
}
}
})
```
---
#### How To Run
Files in the `publicDir` directory are cached before the server is created
```
node server.js
```
#### Dev Mode
Files in the `publicDir` directory are read from storage every load
```
node server.js --dev
```
---
In a web browser, go to http://localhost:8080