0.4.3 • Published 5 years ago

nodejs-web-server v0.4.3

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

Nodejs-Web-Server

How to use

Nodejs-Web-Server is a wrapper around express.js, handlebars and jsonwebtoken.

Every app.listen method looks basically like this:

app.listen(Method, Path, callbacks)

To specify the Port add PORT to the .env file together with the port number.

PORT=Port_number

Methods

  • GET

  • POST

  • STATIC

  • API


GET

app.listen("GET", "/path/to/listen", (req, res) => {

});

callbacks:

  • req

  • res


POST

app.listen("POST", "/path/to/listen", (body, req, res) => {

});

callbacks:

  • body

  • req

  • res


STATIC

app.listen("STATIC", "/favicon.ico");

parameters

  • path to static file in static directory (root)


API

app.listen("API", "/api/v1/test", (decoded, body, req, res) => {
});

If the provided JWT-token is not valid, all callbacks will be null.

The JWT-secret is stored in an .env file under the tag SECRET:

SECRET=this_is_a_secret

callbacks:

  • decoded jwt token

  • body

  • req

  • res

Templating

nodejs-web-server also has a built-in templating engine built around handlebars. to use it, just type:

let  template = app.template("View Name", {
	data1:  "title",
	data2:  "logo"
});

I would recommend this in use together with the GET method.

app.listen("GET", "/path/to/listen", (req, res) => {
	res.send(app.template("view", {
		data1:  "title",
		data2:  "logo"
	}));
});

Required Directories

all directories have to be in the app's root path

  • static (only required if you use static function)

  • views (only required if you use the templating engine)

MySQL-Query

To use the built in MySQL-Driver use

app.db.query("SELECT NOW()", null, (err, res) => {
})

To use multiple SQL-Statements use

app.db.queryMultiple("CREATE DATABASE testtable; USE testtable; ...", null, (err, res) => {
})

For more information visit nodejs-mysql-driver.

0.4.3

5 years ago

0.4.2

5 years ago

0.4.1

5 years ago

0.4.0

5 years ago

0.3.2

5 years ago

0.3.1

5 years ago

0.3.0

5 years ago

0.1.9

5 years ago

0.1.8

5 years ago

0.1.7

5 years ago

0.1.6

5 years ago

0.1.5

5 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago