app.get('/', function(req, res, next) {
res.send('hello world');
})
For comparison, flask: @app.route("/", method='GET')
def hello():
return "Hello World!"
It's really close, but I find the NodeJS approach even simpler and easier to understand. Need to access the request? use `req`. Need to access the response to set headers or something? use `res`. Is your function actually a middleware? use `next`. It doesn't get much simpler, assuming you understand node's semantics well (as in "return"ing a value doesn't mean it gets sent).Django/Rails required whole project scaffolds and usually a separate routes and handlers files and knowing a whole bunch of stuff. I'm not even going to get into what frameworks like Spring/Struts required.
NodeJS made it dead simple to get a HTTP server up and running in something like <10 lines of code.
People shit on JS and NodeJS every chance they get, but innovations like the amazing standard library (and express), along with npm's ease of use really pushed the field forward IMO. While I'm praising node I might as well say that node got decent bolt-on (gradual) type system support way faster than the other popular dynamic languages as well, but they got there through transpiling which also looked (is?) ridiculous the first time it became well-known. I find Typescript much more approachable than typed python[0]. Is typed ruby even a thing[1]? I don't keep up with ruby so I'm not sure.