Using Servercn in a JavaScript Project
Servercn components are written in TypeScript, but JavaScript developers can still use them by building the components and using the compiled JavaScript output.
If you encounter any issues while following the steps, feel free to join our Discord server for help and support.
Follow the steps below to use servercn components in your Node.js + JavaScript project.
Set Up Your Development Environment
First, let's ensure you have the necessary tools installed globally:
npm install -g typescriptThis installs:
- TypeScript compiler (
tsc) - to compile TypeScript to JavaScript
Verify the installation:
You should see the TypeScript version number (e.g., Version 5.x.x).
Install Servercn Foundation
First, initialize Servercn in your project.
npx servercn-cli initYou will be prompted to choose a project foundation:
Select the foundation that matches your preferred database and ORM stack.
After selecting the foundation, you will be prompted with a few additional setup options:
Configure these options based on your project preferences. Once completed, Servercn will generate the project structure and install the required dependencies.
Configure Environment Variables
Configure your env variables in .env
If you encounter any issues while following the steps, feel free to join our Discord server for help and support.
Verify Package Scripts
Before starting the server, ensure that your package.json contains the following scripts:
These scripts handle development, production, type checking, and code formatting for your project.
Start Your Server
Start the development server by running:
Once the server starts successfully, you should see output similar to this:
This means your backend is running successfully.
Configure tsconfig.json
Update your tsconfig.json file by replacing its content with the following:
Add Servercn Component, Schema..
Now add the component you want.
npx servercn-cli add error-handlernpx servercn-cli add oauthnpx servercn-cli add email-servicenpx servercn-cli add file-uploadCompile Your Server
After adding or updating any component, always run:
This will generate the dist folder containing the compiled server files.
Copy JavaScript Code
Now, you can copy the compiled JavaScript code from the dist folder into your JavaScript project — no TypeScript knowledge required.
Repeat Component Addition
Repeat the steps from Add Servercn Component for any additional components you want to include in your project.
If you encounter any issues while following the steps, feel free to join our Discord server for help and support.
Getting Help
- Documentation: Check component-specific docs in
/docs/** - Issues: Report issues on GitHub
- Community: Join our community discussions
- Discord: Join our Discord community.
While this guide helps you use Servercn in JavaScript projects, consider learning TypeScript basics. It'll make integrating Servercn components even easier and unlock better IDE support!