You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
1.8 KiB
Markdown
69 lines
1.8 KiB
Markdown
# Basic procedure to init a JS proyect
|
|
This basic repository shows how to prepare basic JS apps to run and test in Unix like OS. The guide use the `serve` node package installed globally; alternally you can use `live server` extension in visual studio code to mount a basic server for testing.
|
|
|
|
## 1. Create the project directory
|
|
|
|
```sh
|
|
mkdir my-js-project
|
|
cd my-js-project
|
|
```
|
|
|
|
## 2. Create the basic files
|
|
|
|
```sh
|
|
touch index.html
|
|
touch script.js
|
|
```
|
|
|
|
**index.html**
|
|
```html
|
|
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>Test JS</title>
|
|
</head>
|
|
<body>
|
|
<h1>Hello Blink!</h1>
|
|
<button onclick="sayHello()">Click me</button>
|
|
<script src="script.js"></script>
|
|
</body>
|
|
</html>
|
|
```
|
|
|
|
**script.js**
|
|
```js
|
|
function sayHello() {
|
|
alert("Hello from JS!");
|
|
console.log("Hello from script.js!");
|
|
}
|
|
```
|
|
|
|
## 3. Install a simple static server
|
|
If you want to serve this app via a web browser use:
|
|
```sh
|
|
npm install -g serve
|
|
```
|
|
This will install globally, if you already do not have installed, and then you can use later for this or further js projects:
|
|
```sh
|
|
serve .
|
|
```
|
|
By default it serves on `http://localhost:3000`
|
|
|
|
## 4. Access it in the web browser
|
|
Once you execute the `serve` commmand a prompt will let you know where your server is serving:
|
|
|
|
```sh
|
|
Serving! ││ ││ - Local: http://localhost:3000 ││ - Network: http://172.18.0.2:3000
|
|
```
|
|
thus, you can visit it locally or in other device with the `network` address.
|
|
|
|
**Note: if you are using Blink Shell app for iPad** you must open other Blink terminal and forward the the exposed port:
|
|
```sh
|
|
Blink> build port add htools 3000 3000
|
|
```
|
|
|
|
after that you will be able to open the app only directly from your iPad if you did it by `Blink Build`. Otherwise, the app will be abaileble at the provided URL.
|
|
|
|
|