Repository URL to install this package:
|
Version:
3.0.2 ▾
|
node, npm, docker
mkdir ${PROJECT_NAME}touch .npmrcregistry=https://npm-proxy.fury.io/bixqGu-AWRynjiisoc9n/touchto/
strict-ssl=true
ca=
Add these contents above
npm init, follow on screenpackage.json
find and replace the “scripts” declaration in package.js with:"scripts": {
"start": "node ${npm_package_main}",
"debug": "DEBUG=touchto* DEBUG_COLORS=1 node ${npm_package_main}"
}
npm install --save touchto-core
This command d/l’s a slew of node modules necessary for TouchTo-core into the node_modules directory.In base project directory 6. index.js
#!/usr/bin/env node
var express = require('express');
var debug = require('debug')('touchto:server');
var app = require('touchto-core/app');
var http = require('http').Server(app);
require('touchto-core/database');
server = http.listen(3000, function(){
debug('HTTP listenting at: %s', server.address().port);
});
At this point you have a fully capable installation of Touchto Core. You can test it by running it with npm start or npm run debug
Example console output after going to localhost:3000 on your browser
npm start
WARNING: No configurations found in configuration directory:...config
WARNING: To disable this warning set SUPPRESS_NO_CONFIG_WARNING in the environment.
GET / 404 4.453 ms - 9
You get a 404 response because Touchto Core is configured to use endpoints housed in
server/routes-open/
server/routes-rest-open/
—and—
server/routes/
server/routes-rest
Let’s make a public route in server/routes-open/. There is a numerical naming convention for routes files. Start with 000-.js and progress to 001-.js onward.
mkdir -p server/routes-open
touch server/routes-open/000-index.js
var base, debug, express, namespace, path, router;
path = require('path');
namespace = path.basename(path.dirname(module.filename));
base = path.basename(module.filename, path.extname(module.filename)).match(/^(?:\d{0,}-)?(.+)/)[1];
debug = require('debug')("touchto:" + namespace + ":" + base);
express = require('express');
router = express.Router({
caseSensitive: true
});
router.get('/', function(req, res, next) {
res.send('Howdy!');
});
debug('Router instance ready');
module.exports = router;
Now let’s make a new endpoint/webpage and the html, css, and js for it. First we’ll need to create some directories.
mkdir -p client/scripts <— JS
mkdir -p server/views <— HTML
mkdir -p client/styles <— CSS
touch server/routes-open/001-foo.js
touch client/scripts/main.js
touch server/views/hello.html
Add the following line to our previously created 000-index.js file AFTER the declaration of the router variable:
router.use('/js', express.static(path.join(__dirname,'../../client/scripts')));
This line tells the app router where client requested js files are located.
001-foo.js file:var base, debug, express, namespace, path, router;
path = require('path');
namespace = path.basename(path.dirname(module.filename));
base = path.basename(module.filename, path.extname(module.filename)).match(/^(?:\d{0,}-)?(.+)/)[1];
debug = require('debug')("touchto:" + namespace + ":" + base);
express = require('express');
router = express.Router({
caseSensitive: true
});
router.get('/', function(req, res, next) {
res.render('hello');
});
debug('Router instance ready');
module.exports = router;
console.log(‘You got some js running!’);
<script src="js/main.js"></script>
<p> Heyup! </p>
localhost:3000/foo.
Stop and restart the app with: Ctrl-C then, npm start or npm run debug and refresh the page and you should get a Heyup! along with console output in your dev console.If you have docker installed you can dev through a running docker image. This is preferred for portability reasons.
From the your Touchto Core base directory.
docker run --name touchto-core --rm -it -p 80:3000 -v "$PWD":/app -w /app node:alpine shCommand Explanation: Run a docker named touchto-core, remove it after exits, give it a terminal, forward app port 3000 to host port 80, share local volume PWD (Touchto app directory) with docker image directory /app, make the working directory /app, base the image off node:alpine in hub, and give user a sh shell prompt.
Once it’s running type npm start. Go to localhost and localhost/foo.
If the --port number is not the default 80, aka. 8080:3000, then goto localhost:8080.