1

I'm challenged with the task to explore node.js as an alternative to ASP.NET Web API in providing a RESTful API.

I've been developing ASP.NET Web API for some time now and have got used to having certain things within that framework, I'm wondering what others are doing down the node.js route for some of these things: -

  1. What ORM to use against MS SQL instead of Entity Framework
  2. Is there a nice way of handling the routing similarly to what you get in Web API with the route template (routeTemplate: "api/{controller}/{id}")
    • I'm using Express so far and haven't found a way of applying something like this at a 'top level' so that I can have separate controllers...

That's it so far, I'm sure there are many, many more questions to come but those are my immediate concerns if anybody can help with these?

1 Answer 1

2
  1. For ORM the 2 most libraries used are knexjs and sequelize, however, I prefer knex.
  2. For the mapping part, as far as I know, there isn't a way to do it like in the c#. Usually what I do is, in the app.js load a file with my routes index. Here is an example,

In your app.js

app.use('/', require('./backend/routes/index'))

Then, in your routes/index

import express from 'express'

const router = express.Router()

// GET /
router.get('/', function (req, res) {

})

// GET /countries
router.get('/countries', (req, res, next) => {

})

// POST /subscribe
router.post('/subscribe', checkAuth, generalBodyValidation, (req, res, next) => {

})

// All routes to /admin are being solved in the backend/routes/admin/index file
router.use('/admin', require('./backend/routes/admin/index'))

module.exports = router

Your admin/index file can be import express from 'express'

const router = express.Router()

// POST /admin/login
router.post('/login', (req, res, next) => {

})

module.exports = router

With this, you will be able to have a better structure for your routes.

Hope this asks your questions, if it does mark my answer as correct, if not tell me what you didn't understand :D

Sign up to request clarification or add additional context in comments.

2 Comments

Great informative answer, thank you very much! Just wondering, have you had any experience with TypeORM?
Unfortunately, I don't. I never used typescript, but if you willing to use it seems to be a good library.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.