These are chat archives for FreeCodeCamp/Help

27th
Mar 2019
Diogo Esteves
@EstevesDiogo
Mar 27 00:07

Hello guys i am trying to show a name before my routes on angular can any one help me?

´site.com/(prefix)/home

'site.com/(prefix)/details/detail/1'

site.com/(prefix)/users/user/3/favcolor

....`

Brad
@bradtaniguchi
Mar 27 00:58
@EstevesDiogo What is the prefix? The name? Name of what? Is the name dependent upon the build, the user, the url? (like github) what makes it different than the numbers in the url params?
nsonhouse
@nsonhouse
Mar 27 01:59
Can someone tell me what I am doing wrong here? I am unable to display a query to the browser. But I am able to see it in the console.
// Connection string parameters
const sql = require('mssql');

 let dbConfig = {
    user       : 'sa',
    password   : '******',
    server     : 'localhost',
    database   : 'testDB',
    port       : 1433
};

function getData() {
        let connection = new sql.ConnectionPool(dbConfig);

        connection.connect()
        .then(function() {
            let req = new sql.Request(connection);
            req.query("SELECT * FROM status")
            .then(function(recordset) {
                console.log(recordset);
                connection.close();
            })
            .catch(function(err) {
                console.log(err);
                connection.close();
            });
        })
        .catch(function(err){
            console.log(err);
        });

};

getData();
const express = require('express');  // web framework

const dbConfig = require("./controllers/dbConfig");
let bodyParser = require('body-parser');
let path = require('path');
let http = require('http');

const app = express();

app.use(bodyParser());
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');

let publicPath = path.resolve(__dirname, "public");
app.use(express.static(publicPath));

app.get('/', function(req, res) {
    res.render(getData());
});

const port = 3000;
app.listen(port, () => console.log(`app listening on port ${port}!`));
Brad
@bradtaniguchi
Mar 27 02:04
@nsonhouse
This doesn't work the way you expect
res.render(getData());
you need to get the data that you are printing in console.log and return that using express. Logging it to the console doesn't give anything to express
nsonhouse
@nsonhouse
Mar 27 02:06
Yes, I wanted to see the output, so I know it's there. Now you said it's not getting to Express. Please elaborate.
Brad
@bradtaniguchi
Mar 27 02:07
what does the getData method return?
nsonhouse
@nsonhouse
Mar 27 02:09
Remember last night I was asking about writing a function that would connect to the DB and return a query. Well that is what I am attempting. It just a SELECT *
Brad
@bradtaniguchi
Mar 27 02:10
That's not what I mean, like Javascript wise your function does not return any data. Like:
function getHI() {
  return 'hi';
}

res.send(getHI()); // you will see 'hi' in your browser
nsonhouse
@nsonhouse
Mar 27 02:11
OK
Brad
@bradtaniguchi
Mar 27 02:12
You will probably need to return a promise from your getData() method and use .then on it within your express code, that way when the data comes back you do something like:
getData().then((data) => res.send(data));
Jake
@JakeDVirus
Mar 27 02:12
I'm too much confused whether to use cms or not (in production) and why? and which cms to use if i have to (like wordpress, ghost, spurt commerce)?
nsonhouse
@nsonhouse
Mar 27 02:12
So instead of console.log(recordset)
Brad
@bradtaniguchi
Mar 27 02:12
console.logs are fine, but don't do anything besides printing to the console
nsonhouse
@nsonhouse
Mar 27 02:14
Now I'm confused. Should the function get the data or should the app.get get the data?
Brad
@bradtaniguchi
Mar 27 02:15
They are doing two different things, 1 is a callback for express, the other is you getting data from the database using getData
both are "async" as such they are callbacks/promises, which both handle the same task of dealing with async data
nsonhouse
@nsonhouse
Mar 27 02:18
So how do I execute this without being repetitive. My goal is to execute all the CRUD operations with a single connect function and pass the query. But now it seems the query should be defined in the route vs a function, since you said my function does not give any data to express.
pselling520
@pselling520
Mar 27 03:26

Hey all, just started using FreeCodeCamp, but I can't type anything in the section where we're supposed to put our code. The only keys that seem to work for me are tab, enter, space, delete, and the arrow keys.

I'm using Chrome and Windows. Every time I type, I type any letter, an error pops up in the console (ctrl+shift+j) saying:
Uncaught TypeError: Cannot read property 'length' of undefined at Function.e.selectedText (editor.main.js:31) at f (editor.main.js:31) at HTMLTextAreaElement (editor.main.js:31)

Has anybody seen this before?

caoshucs
@caoshucs
Mar 27 06:12

<style>
.red-text {
color: red;
}
</style>

<h2 class="red-text">我家的猫咪</h2>

<p class="red-text" font-size:16px>在大家心目中,猫是慵懒的可爱的化身,它可以睡饱了再起来吃饭,可以逗趣小耗子,可以卖得了萌,使得了坏,这样百变的小怪兽就集结在一只宠物上,怎能不惹人怜爱。</p>

<p font-size:16px>养动物有的时候,就是介于爱与恨之间,当你钦羡别人萌宠这么可爱的时候,你一定没有想过,狗狗和猫猫会到处拉屎,甚至会屯老鼠,啃鞋子,用爪子爬门,你不理它,它就挠你,你要对它发脾气,它会比你更来劲。所以,狗猫慎入,没有一定的准备,切勿随便去侍养动物。它们一旦认定你了,你就是它们的主人,如果你抛弃它们,它们必定心中重创。</p>.

这个font-size:16px 如何设置
请教大家
Diogo Esteves
@EstevesDiogo
Mar 27 16:01
@bradtaniguchi hi brad on my comp. project we are migrating from knockout js to angular and we are using the 2 apps at the same time and making redirects with a reverse proxy.
On the old project we have on URL the appName and on this one we want to have the project name on the url to.
so how can i do that?
Brad
@bradtaniguchi
Mar 27 17:23
So your basically asking if you can provide a prefix in all the angular routes? Yes, just add it to the root routing paths as a prefix for all paths. I think that's what you want. On the topic of using 2 apps at the same time, I wouldn't take that approach and just migrate the entire app at once into Angular. Mixing and matching doesn't get you anything beyond performance hits and bugs (like the one your mentioning right now) which just increase the amount of time it will take to get things done
Diogo Esteves
@EstevesDiogo
Mar 27 18:45
@bradtaniguchi Thank you
nsonhouse
@nsonhouse
Mar 27 19:45
@bradtaniguchi Brad, you never got back to me... Did you fall asleep on me?
Brad
@bradtaniguchi
Mar 27 19:49
@nsonhouse I headed home after my last comment and didn't look back to see if you response. There are lots of ways to do this, but generally the pattern is always the same when dealing with promises and async actions in JS. Your missing a way to return the promise from your getData function, which is then resolved in the route, so you can use the promise callback to send the data back to the end-user.
I already posted the code the router will need, I left how to change the getData() function up to you, so it returns the promise call. (your already using the promise call in the function to console.log, just remove this and return the db call that returns the promise)
May Kittens Devour Your Soul
@diomed
Mar 27 21:17
s
@caoshucs choto! kinichiro! dozo! moto penekeku!
Christopher McCormack
@cmccormack
Mar 27 21:51
@diomed very nice :)