npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@singhsa_6666/assignment-1

v1.0.0

Published

Convert this from JS to typescript.

Downloads

1

Readme

This project contains the backend for a simple todo app

Convert this from JS to typescript. We have a simple backend for a TODO application. First, just go through the codebase and make sure you understand it. There is a postman collection for you to try this out locally Run node index.js to run the app locally and try all the routes in postman. You WILL need mongoDB running locally, or a cloud mongoDB instance. Please replace the mongoDB url in index.js with your own mongoDB url.

Steps to follow

  • First step in doing this is to convert the JS files to TS files (replacing the extension of all files).
  • Next, run tsc --init to create a tsconfig.json file (make sure u already have tsc (npm i -g tsc)).
  • Set strict to false for now until we add all types.
  • Set outDir to dist so as to not pollute your original folder
  • Try running it, notice the errors that you see.
    • The errors you will see should be of the format
    • 'mongoose' was also declared here.
    • Move all requires => imports to fix these errors. This is related to a bug bug in TS (https://stackoverflow.com/questions/35758584/cannot-redeclare-block-scoped-variable)
    • For example, convert
      • const mongoose = require('mongoose'); to
      • import mongoose from 'mongoose';
    • Same thing for exports, export using the modern ES6 syntax
      • module.exports = mongoose.model('Todo', todoSchema); to
      • export default mongoose.model('Todo', todoSchema);
  • Now typescript shouldnt complain, but this isn't the end. We still have to flip on strict to actually see errors.
  • Check out the errors that you see
  • Next, run npm install -D @types/node to install the types for node.
  • Next, run npm install -D @types/express to install the types for express.
  • Next, run npm install -D @types/mongoose to install the types for mongoose.
  • You will see a bunch of Parameter 'req' implicitly has an 'any' type. errors. Fix these by adding types to all the functions.
    • Express exports the Request and Response types, use them to type the req and res params.
    • If you ever get stuck, initially you can use the any type
    • You can also just flip noImplicitAny to false in tsconfig, but that's cheating.
  • You will see req.userId complains everywhere, and rightfully so. We've added userId key to an object that doesn't expect it. Fix this by sending over the id via the headers.
  • Create types for the inputs to all routes (for eg User, Todo) and use them when u decode the body.
  • Try running tsc now, you should see no errors.