CodeIgniter Forums

Full Version: nodejs tips and tricks
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4 5
(09-21-2018, 11:07 PM)skunkbad Wrote: [ -> ]
(09-21-2018, 06:37 PM)ignitedcms Wrote: [ -> ]@skunkbad dear lord! I looked over a reactjs tutorial compared to vuejs and the difference was huge, the syntax for vuejs is less verbose easier to figure out etc. It's just a shame reactjs has the bigger market share. Have you tried vuejs? It is a pure job to work with.

I’ve tried both, and initially preferred vuejs. If I can only pick one, I’ve got to go with the money maker.

I completely agree, that's why I picked nodejs over golang as the job section seemed to show greater demand for nodejs jobs however, that has put me in a bit of a dilemma now as I was really keen to learn vue over the other two frontend frameworks.
(09-21-2018, 11:31 PM)ignitedcms Wrote: [ -> ]
(09-21-2018, 11:07 PM)skunkbad Wrote: [ -> ]
(09-21-2018, 06:37 PM)ignitedcms Wrote: [ -> ]@skunkbad dear lord! I looked over a reactjs tutorial compared to vuejs and the difference was huge, the syntax for vuejs is less verbose easier to figure out etc. It's just a shame reactjs has the bigger market share. Have you tried vuejs? It is a pure job to work with.

I’ve tried both, and initially preferred vuejs. If I can only pick one, I’ve got to go with the money maker.

I completely agree, that's why I picked nodejs over golang as the job section seemed to show greater demand for nodejs jobs however, that has put me in a bit of a dilemma now as I was really keen to learn vue over the other two frontend frameworks.

Gotta remember, at least from what I gather, vues' popularity seems propped up almost entirely by laravel hipsters. That's not to say it's not worthy of being learned and used, but you have to wonder where vue would be without laravel and laracasts. If vue jobs were slightly more prevalent it might seem more appealing. I think you're going to find that with more experience that react is actually quite easy. Redux makes setup a little complex, but even that will make sense after you do it a couple times.
(09-22-2018, 07:00 AM)skunkbad Wrote: [ -> ]
(09-21-2018, 11:31 PM)ignitedcms Wrote: [ -> ]
(09-21-2018, 11:07 PM)skunkbad Wrote: [ -> ]
(09-21-2018, 06:37 PM)ignitedcms Wrote: [ -> ]@skunkbad dear lord! I looked over a reactjs tutorial compared to vuejs and the difference was huge, the syntax for vuejs is less verbose easier to figure out etc. It's just a shame reactjs has the bigger market share. Have you tried vuejs? It is a pure job to work with.

I’ve tried both, and initially preferred vuejs. If I can only pick one, I’ve got to go with the money maker.

I completely agree, that's why I picked nodejs over golang as the job section seemed to show greater demand for nodejs jobs however, that has put me in a bit of a dilemma now as I was really keen to learn vue over the other two frontend frameworks.

Gotta remember, at least from what I gather, vues' popularity seems propped up almost entirely by laravel hipsters. That's not to say it's not worthy of being learned and used, but you have to wonder where vue would be without laravel and laracasts. If vue jobs were slightly more prevalent it might seem more appealing. I think you're going to find that with more experience that react is actually quite easy. Redux makes setup a little complex, but even that will make sense after you do it a couple times.

I've put some stuff in my Vuejs thread if you wish to check it out.

In the mean time, I'm getting on very nicely with expressjs.

Just thought I'd share some of the more useful plugins I found:

Code:
"bcryptjs": "^2.4.3",
    "body-parser": "^1.18.3",
    "dateformat": "^3.0.3",
    "express": "^4.16.3",
    "express-handlebars": "^3.0.0",
    "express-validator": "^5.3.0",
    "handlebars": "^4.0.12",
    "multer": "^1.3.1",
    "mysql": "^2.16.0",
    "nodemailer": "^4.6.8",
    "squel": "^5.12.2",
    "validator": "^10.7.1"

^Of the above I really liked squel, it is kinda like a helper for sql queries for nodejs. Very useful when used in conjunction with mysql, a bit like the CI query builder.

https://hiddentao.com/squel/

I've created a persistent db connection, figured out how to do routing properly, implemented a simple MVC structure, served files, implemented a file upload with error handling, hashed a password, CRUD operations to mysql, email facilities.

All I really need to figure out next is sessions.
Hi Guys, just about to finish sessions inside expressjs and it was super simple, I guess you could store these in the database but it seems fine as is.

Here is a handy tutorial.

https://www.youtube.com/watch?v=aT98NMdAXyk

The only thing left to do is write a few helper functions like codeigniter's in my system folder and I'm pretty much done.

For zipping files I found this.

https://www.npmjs.com/package/express-zip

For inflector helpers etc I thought this was a decent package.

https://www.npmjs.com/package/string
OK I just spend hours trying to make the sessions work - but every time I went to another the page the sessions was cleared.

Code:
//express session test
var session = require('express-session');


app.use(session( {
  secret: 'secretpassword',
  resave: false,
  saveUninitialized: true,
  cookie: {secure:false }
}));

Finally, after much googling I figured out what it was. It wasn't that the sessions weren't working, it was because I was using an external library hosted on cdnjs to load a html page.

So essentially it is a CORS issue that causes the sessions not to persist. This is just a heads up if anyone else has the same problem.
Thus the solution to get cors working is to install it from npm


Code:
npm install cors --save

var cors = require('cors');

//set cors
app.use(cors());

And that's it now you can use vuejs hosted externally, or whatever you want, but that took ages to figure out.
Hi Guys this is the penultimate topic I want to cover regarding nodejs, it is socket.io

I thought this was a very useful tutorial.

https://www.youtube.com/watch?v=tHbCkikFfDE
https://socket.io/

The only other thing after this is probably trying to wrap my head around asynchronous functions, async / promises.
One last thing if you're on plesk, which I am using deployment should be fairly straight forward, I'm going to do a test later this week.

https://www.youtube.com/watch?v=9E0wDCUOY2c&t=4s

https://www.plesk.com/blog/product-techn...lesk-onyx/
With regard to setting up node js in a production environment, you might find this article interesting.

But before you get too deep into node you might want to consider Python. Seems like it will be in the "high demand" category as a programming skill.
(09-27-2018, 07:37 AM)dave friend Wrote: [ -> ]With regard to setting up node js in a production environment, you might find this article interesting.

But before you get too deep into node you might want to consider Python. Seems like it will be in the "high demand" category as a programming skill.

Great article thank you for your opinion. I already know python quite well, as it is a scripted language it will suffer the same bottlenecks as PHP, unless they rewrite it for server side only.

I personally doubt, it will gain that much traction because the front end has always been javascript and is now entrenched in the industry, actually, I was considering learning one or the other (golang or nodejs) I went for nodejs because of this and I had a look at the jobs section.

Now that is not to say it could change over time, if it does, then I guess we learn that new trend. Everything in web changes, in any case I am extremely happy with what I have so far. I would urge anyone who is considering learning this to give it a go.
Pages: 1 2 3 4 5