Skip to content

Instantly share code, notes, and snippets.

@rpragana
Last active June 19, 2017 00:11
Show Gist options
  • Save rpragana/8535e89450d7db76132a8e1eb90d7e57 to your computer and use it in GitHub Desktop.
Save rpragana/8535e89450d7db76132a8e1eb90d7e57 to your computer and use it in GitHub Desktop.
NodeJS REPL
<!doctype html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<h1>Servidor web</h1>
<p>Este servidor Express serve arquivos estáticos.</p>
<a href="/teste">Rota "/teste"</a>
</body>
</html>

NodeJS REPL (Read-Eval-Print-Loop)

  • server_static.js
  • sget.js
  • index.html
#!/usr/bin/env nodemon
var fs = require('fs');
var path = require('path');
var express = require('express');
var app = express()
app.use(express.static(__dirname + '/'));
app.listen(8000);
console.log('Aponte seu navegador para https://localhost:8000/');
// -- incluindo o REPL na nossa aplicação
var s = "Uma mensagem para verificação."
var t = "Outra mensagem"
var repl = require('repl');
var rinst = repl.start('> ');
rinst.context.s = s
rinst.context.app = app
var appret = app.get('/teste', function(req, res) {
res.send('<h1>Express server</h1>'+
'<p>Retornando pela rota "/teste"</p>');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment