express.js sample apps [closed] - node.js

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
Improve this question
I am starting an express.js project. I want to look at code of exiting large apps, especially their file system structure. Anyone knows of apps that use express.js and are on github?

Here's my layout.
./myapp
./public -- static files
./modules -- modules I made for reusability
./routes -- like controllers
./log -- app log file
./views -- ejs views
./config -- config.development.js, config.global.js
./templates -- email templates (text/html in ejs)
./pid -- for server
./init -- git post-receive hook for deploy
./models -- mongoose schemas

Take a look at my answer to ExpressJS How to structure an application. You can also look at the repo for my own web site, which although neither large nor exciting, is an express app and has a pretty sane filesystem and code organization scheme (IMHO).
Of coures, browse the list of ExpressJS applications on the main Express site. Not sure which if any are open source, but have a look through those.

Express is kind of notorious for not really having any specific guidance on how to lay out the folder structure and build big apps. To be fair, it's not really intended to be a "Rails", it's more of a light layer that simplifies basic HTTP features.
There may be some Express examples on Github, but none off the top of my head.
You may want to take a look at RailwayJS which is a lot closer to the expected "Rails" on top of Express. You may also want to take a look at Geddy which is used for large-scale apps. Geddy is not Express-based, but has more explicit guidance on how to structure everything.

In my express app, I have more or less this structure:
project
|--app.js
|--bin
| `--shell scripts and stuff*
|--docroot
| `--static files, etc*
|--node_modules
| `--npm downloads go here*
|--lib
| |--vendor
| | `--jar files and stuff*
| |--my-custom-middleware1.js
| `--my-custom-middleware2.js
|--package.json
|--README.md
`--templates
`--a bunch of templates*
Works fairly well for what I need.

This not a very large scale project but it gives you a basic idea about how to structure you application it's a REST API https://github.com/khurrumqureshi/BotnikServer

Have a look at the examples of express that you can find at the github repository. If you are into MVC there is also an example for it. They give you a good first idea on how to structure your app.
More on how to structure your app is in the express faq under "How should I structure my application?"

There are a ton of apps on github that use express. For a large project you can look at krakenjs.com. Which is not really an app but more of a structure for an app that was created by paypal when they switched from java to node.js.
You can also look at more full stack app structures like mean.io or meanjs.org if you want to use angular.js and mongodb. Even if you don't you can get an idea of how they structure their code.

Related

Best Resource for learning MEAN Stack [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
I started this question from a problem I was having following a tutorial(listed below). Some people felt it wasn't a good enough question. So I am re-stating my question.
What is the best resource for learning & understanding the MEAN Stack?
////Old post
Alright, I am at ends with this. I'm following this tutorial and I've gotten to the point where I need to fork a project on github[done] and run npm install. thiss is what the directions say:
At this point, you’ve done essentially all you need to do to run a MEAN stack application. You can simply clone/fork https://github.com/vkarpov15/mean-stack-skeleton , start a “mongod” process, navigate to the git repo, and run npm install -d
So what the hell does that mean? Navigate to the git repo and then run a command. Mongod is running, I'm in another shell session...now what?
thanks, I've been digging into this for a day now.
I would recommend the MongoDB free online course for Node.js developers, see: MongoDB/nodeJS course. It goes through all of this at the beginning. They repeat these courses every few months.
Answer to original question: It means go to the directory that was created when you ran git clone, in which you will find the package.json file.
The node package manager (npm) will parse the contents of package.json and download any other required dependencies -- in this case Express, MongoDB, Mongoose, Jade, etc.
Here's a tutorial for beginners that demonstrates how to build an enterprise-style app covering (installation, server, database, client):
MEAN Stack Tutorial
Disclosure: I wrote the tutorials.
I used many different resources. Since there are four components to the stack:
Angular:
Lynda.com "Ray Villalobos" does a great job going over angular.
Codeschool.com they have two good courses on angular, one is free.
Pluralisight.com They have a good intro course and more in-depth courses I still refer to.
Node.js:
Codeschool.com has a good course on node that cleared up a lot of questions.
Express
Codeschool.com also has a great course on this
Lynda.com "Ray Villalobos" has a good course featuring express
Mongo
MongoDb has a good amount of tutorials through youtube
https://scotch.io/ was also a great resource and starting point for me for the entire stack.
They also have an online book on the MEAN stack.
Prerequisite for learning MEAN is to know MongoDB, Express.js, Angular.js and Node.js.
The best place to start learning MEAN Stack is to install sample MEAN application.
MEAN website(http://learn.mean.io/) provides step by step procedure to install mean application. The MEAN Website also explains the various folders inside the application in easy steps. I personally think MEAN website(http://learn.mean.io/) provides comprehensive documentation to understand MEAN.
If you are want to learn the MEAN through books. Please find list of books for learning MEAN
Getting MEAN with Mongo, Express, Angular, and Node by Simon Holmes
MEAN Web Development by Amos Q. Haviv Full Stack JavaScript
Development With MEAN by Colin J Ihrig

Automating Node and Angular frontend/backend Integration, production preparation and deployment? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I have been experimenting with Node.js for a while and have hacked together simple projects with Express, Hapi and Restify. The frontends on these small projects were very small and limited, as I was primarily focused on the backend, so I never had the need to automate a lot of the details when deploying them to production servers.
I recently started getting into front end development and stumbled across some great automation tools; Yeoman (overall workflow), Yo (for scaffolding), Grunt (automation) and Bower (for dependencies).
I absolutely love the workflow of these tools and they have gotten me really excited about trying to learn front end development, structuring and workflow. However, learning all of this has also raised questions on the proper way to automate other areas of workflow that integrate the front and back ends:
1) Should I be maintaining the frontend and backend in the same repository? They are both written in JavaScript but it seems semi clunky. I know this is a matter of preference but I would love to see some thoughts on current best practices. Would it be best to have the public directory in my app be a sym link to another.
2) How do I wire my front end to my backend? Specifically talking about socket.io calls. I am not sure the best way to automate how to best set this variable. In the backend I would use process.env, but I am unsure how to accomplish wiring them together based on test, production settings. I do not want to hand change this everytime I deploy to server.
1) I like the idea of keeping them in the same repository. It makes your life so much easier as you go along. The one thing you will feel happy is once your server and web pages are being served from same web server, you dont need to deal with any of the CORS issues. Or you don't need to have a reverse proxy just to resolve CORS issue.
2) We use angular js with socket.io calls. Since you use yeoman, you can read a config file into the Gruntfile.js like this. grunt.file.readJSON('config.json'). You can reuse your grunt scripts if you have a CI.
nodeServer : {
prod : {
port: 8080, //other params
}
}

What kind of apps can be built using node.js other than real time apps (like chat or multiplayer gaming) [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
Is node.js is only for real time applications like chat or multiplayer games? I know little bit of PHP, Python and ASP.
But I love JS the most. But I am interested in building particular type of application such as-
Content based app (like CMS, forums or community sites)
Utility tools (web2pdf converter, image editing or other frequently used tools)
Business tools (SEO analysis tools etc)
Is node.js only for real time applications??
Edit 0- Can you please give examples of node apps other than real time applications
Edit 1 : can node be used for IO operations or serve static pages over http. Isn't it just another web technology like PHP or ASP.NET
Edit 2 : What can node do that PHP can't. Also anything that PHP can and Node can't.
Node.js is useful for any application that does not involve CPU-bound work.
Node.js is basically just javascript, including the asynchronous aspect of javascript, running outside of the browser. The basic framework it comes with allows you to setup a server really easily, and that's what most people use it for, although it can do most things any other server side language can do (File IO, Networking, Multithreading, etc).
Node.js can be used for most applications, as it's expandable via modules, and has a great developer community. You can see the different companies who use it at http://nodejs.org/industry/.
Some great tutorials can be found by Googling node + the type of project you want to build and you can also find a list of resources in the Readme of their github https://github.com/joyent/node. After you feel comfortable with node, then browse some github node.js repositories, and figure out which modules you want to work with to make your project. Then keep learning!
Javascript is a great language, and node.js is an awesome technology. Good luck!
Node.js is farmost, one of the best technology of its kind. You can build anything out of Node.js, scaling from realtime applications to normal websites. But what makes Node.js standalone from crowd, is its way of handling users request and response. In simple term Node.js come into play when there is lods and lods of traffic coming into your website.

Node-PerfectAPI vs Restify.js vs ExpressJS vs Node-APIServer [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I'm new to ExpressJS. I want to create API's for my service which will be consumed directly by other servers and also a part of it by mobile apps/browsers. I just discovered Restify, Node-PerfectAPI, Node-APIServer and I don't know what the differences are.
Can someone kindly elaborate on the differences of each framework and the advantages/disadvantages.
Why would one choose Express/NodeJS vs. Other Frameworks for creating API'S?
Disclaimer: I am the author of node-perfectapi.
The focus of perfectapi is to make it simple for the developer to go from start to production-ready. It is more abstracted than node-restify. The impact of that is you have less flexibility in the design of your API, but at the same time, you should be able to get something production-ready much quicker, with less expertise.
Both restify and perfectapi have comparable performance.
The links in this answer go to pages that highlight the benefits of each solution.
I'm also working on a similar issue. One of the main difference that may interest you is the performance. I just found a blog post from the developer of "perfect-api" comparing his framework to the 2 others. http://blog.perfectapi.com/2012/benchmarking-apis-using-perfectapi-vs-express.js-vs-restify.js/
A comment states that Restify is doing much better now.
From my (limited) experience, I would say that express.js is easier to use than Restify and provides some nice tools as connect.js which is exposed. For example, this will avoid you the pain of writing a static file server even thought Connect can still be integrated with Restify.
On the other hand, Restify will make some common API tasks much easier. For example, it provides a throttle engine along with an API conversioning system which is really necessary in an environment where you deal with clients you do not control.
You should also consider https://npmjs.org/package/hapi
It looks very promising. There's a talk about the framework in https://www.youtube.com/watch?v=Recv7vR8ZlA where the main contributor to hapi talks about what makes an API framework tick.
If you go to node-perfectapi in github you'll see this message in the readme:
"I am not currently maintaining this package. You should probably look for another tool for what you need."
Therefore I conclude you are better off using restify since this is actively maintained.

Can nodejs be installed on a free webhost [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 5 years ago.
Improve this question
My goal is to create a chatting website. Not so much for the sake of the website, but for the experience so I know how; just something to work towards gradually. I tried long polling, but that always ends up pissing off the webhosts whose servers I'm using. I was told to use nodejs instead. I have some idea of what it is, but no idea how to use it.
I'm guessing that the reason I can't find the answer to this question anywhere is because of how obvious it is... to everyone else.
I've been looking around and all I see are tutorials on installing it on your server when you own the server. I know you can install forums on webhost's servers, so can you also install nodejs?
Yes. You can check the full listing at https://github.com/joyent/node/wiki/Node-Hosting to check each site but it does not categorize it by free hosting..
Some I know of, I personally use Heroku.
Heroku
Nodester
Most standard LAMP hosting companies don't let you run node.js.
I currently recommend you use the Cloud9 IDE to get up and running with not only your tests and development, but also potential deployment. Cloud9 allows you to run your app from their IDE and will provide you with URL to see your app running and get familiar with node.js development.
A more manual way is to find a node.js PAAS (Platform as a Service) such as Joyent or Nodester.
Another one is Open Shift. I use them a lot and they allow you to use your own domain on the free plan. I use Heroku as well and have tried AppFog and Modulus.
But what it comes down to is whether I can use my own domain and how much they throttle my traffic. AppFog and Modulus don't allow custom domains on their free plans and seriously throttle traffic. They will cut your website off if you have one visitor an hour.
Another issue I was concerned about was with the upload of files. In particular, with my website content is added via markdown files. Most node webhosts use a variation on git deploys to update websites, with content supplied by databases. However, if you are trying to run a website without a database, using flat files, then each update must be done by a git deploy. This takes the whole website down and recreates a new website altogether (it just happens to look like the previous one). This will normally take a few minutes. Probably not a problem for a low volume website. But imagine if you are making a blog entry and you deploy it and then notice you've made a spelling mistake. You need to do a deploy all over again.
So, one of the things that attracted me to Open Shift was that they have a reserved area for flat files within your project. You can upload your files there and when your project is re-started these files will be preserved.
Appfog provides a free plan where you can host NodeJS and many other technos.
However, free plans don't allow custom domain name anymore.
There is also the Node.js Smart Machine service from Joyent.

Resources